trustworthiness
- sklearn.manifold.trustworthiness(X, X_embedded, *, n_neighbors=5, metric='euclidean')
Indicate to what extent the local structure is retained.
The trustworthiness is within [0, 1]. It is defined as
Indicate to what extent the local structure is retained.
The trustworthiness is within [0, 1]. It is defined as
where for each sample i, are its k nearest neighbors in the output space, and every sample j is its -th nearest neighbor in the input space. In other words, any unexpected nearest neighbors in the output space are penalised in proportion to their rank in the input space.
(n_samples, n_samples) If the metric is ‘precomputed’ X must be a square distance matrix. Otherwise it contains a sample per row.
Embedding of the training data in low-dimensional space.
The number of neighbors that will be considered. Should be fewer than
n_samples / 2 to ensure the trustworthiness to lies within [0, 1], as
mentioned in [1]. An error will be raised otherwise.
Which metric to use for computing pairwise distances between samples
from the original input space. If metric is ‘precomputed’, X must be a
matrix of pairwise distances or squared distances. Otherwise, for a list
of available metrics, see the documentation of argument metric in
sklearn.pairwise.pairwise_distances and metrics listed in
sklearn.metrics.pairwise.PAIRWISE_DISTANCE_FUNCTIONS. Note that the
“cosine” metric uses cosine_distances.
Trustworthiness of the low-dimensional embedding.
Jarkko Venna and Samuel Kaski. 2001. Neighborhood Preservation in Nonlinear Projection Methods: An Experimental Study. In Proceedings of the International Conference on Artificial Neural Networks (ICANN ‘01). Springer-Verlag, Berlin, Heidelberg, 485-491.
Laurens van der Maaten. Learning a Parametric Embedding by Preserving Local Structure. Proceedings of the Twelfth International Conference on Artificial Intelligence and Statistics, PMLR 5:384-391, 2009.
>>> from sklearn.datasets import make_blobs
>>> from sklearn.decomposition import PCA
>>> from sklearn.manifold import trustworthiness
>>> X, _ = make_blobs(n_samples=100, n_features=10, centers=3, random_state=42)
>>> X_embedded = PCA(n_components=2).fit_transform(X)
>>> print(f"{trustworthiness(X, X_embedded, n_neighbors=5):.2f}")
0.92