from sklearn import datasets
from sklearn.neighbors import KDTree,KNeighborsClassifier,KernelDensity,KNeighborsTransformer
X, y = datasets.load_iris(return_X_y=True)
tree = KDTree(X)
dist_to_knn, idx_of_knn = tree.query(X=X[[3]],k=5)
print(dist_to_knn) # 到k个近邻的距离
print(idx_of_knn) # k个近邻的索引
Sklearn KDTree 的使用
最新推荐文章于 2024-02-02 21:09:30 发布