[MRG+2] Use NearestNeighbors to speed up trustworthiness
@@ -423,9 +423,9 @@ def trustworthiness(X, X_embedded, n_neighbors=5, precomputed=False):
dist_X = X
else:
dist_X = pairwise_distances(X, squared=True)
- dist_X_embedded = pairwise_distances(X_embedded, squared=True)
ind_X = np.argsort(dist_X, axis=1)
- ind_X_embedded = np.argsort(dist_X_embedded, axis=1)[:, 1:n_neighbors + 1]
+ ind_X_embedded = NearestNeighbors(n_neighbors).fit(X_embedded).kneighbors(
+ return_distance=False)
n_samples = X.shape[0]
t = 0.0
