Created
March 27, 2020 05:03
-
-
Save acmiyaguchi/2e95cd2e845d468d9952db834b7b1fbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.neighbors import NearestNeighbors | |
| def create_knn_graph(data, n_neighbors): | |
| ann = NearestNeighbors(algorithm="ball_tree", n_jobs=-1) | |
| index = ann.fit(data) | |
| smat = index.kneighbors_graph(data, n_neighbors) | |
| g = nx.from_scipy_sparse_matrix(smat) | |
| print(nx.info(g)) | |
| return g |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment