<jupyter_start><jupyter_text>K-Nest-Neighbors   1 Unsupervised Neast NeighborsIt acts as a uniform unterface to three different nestest neighbors algorithms: `BallTree`, `KDTree`, and burte-force algorithm based on routines in `sklearn.metrics.pariwise`<jupyter_code>from sklearn.neighbors import NearestNeighbors
import numpy as np
X = np.array([[-1,-1],[-2, -1],[1,1],[2,1],[3,2]])
nbrs = NearestNeighbors(n_neighbors=2, algorithm='ball_tree').fit(X)
distance, indices = nbrs.kneighbors(X)
indices
distance<jupyter_output><empty_output><jupyter_text>We can also use the `KDTree` and `BallTree` classes directly to find the nearest neighbors, alternatively.<jupyter_code>from sklearn.neighbors import KDTree
import numpy as np
X = np.array([[-1,-1],[-2, -1],[1,1],[2,1],[3,2]])
kdt=KDTree(X, leaf_size=30, metric='euclidean')
kdt.query(X, k=2, return_distance=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14492753623188406, 'fraction_numerical': 0.027870680044593088, 'mean_word_length': 7.803921568627451, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '638673', 'license': 'MIT', 'n_tokens_mistral': 352, 'n_tokens_neox': 326, 'n_words': 75, 'path': 'Scikit_Learning/User_Guide/KNN.ipynb', 'repo_name': 'gaufung/Data_Analytics_Learning_Note', 'size': '897'}