#特征值需要哑编码
import numpy as np
from sklearn.neighbors import KDTree
X = np.array([[0,1,1],
[0,1,0],
[0,0,0],
[1,1,1]])
tree = KDTree(X, leaf_size=2)
dist, ind = tree.query(X[:1], k=4)
print(X)
print(ind)
# ind = indices of 4 closest neighbors
print(dist)
# dist = distances to 4 closest neighbors
kdtree 计算数据与样本间的相似度
最新推荐文章于 2022-05-17 19:31:55 发布