小编use*_*551的帖子

使用Python scikit sklearn调用最近邻(knn)分类器的预测函数

我试图调用最近邻居的预测函数并得到以下错误:

AttributeError: 'NearestNeighbors' object has no attribute 'predict'
Run Code Online (Sandbox Code Playgroud)

代码是:

from sklearn.neighbors import NearestNeighbors
samples = [[0., 0., 0.], [0., .5, 0.], [1., 1., .5]]
neigh = NearestNeighbors()
neigh.fit(samples)
neigh.predict([[1., 1., 1.]]) # this cause error
Run Code Online (Sandbox Code Playgroud)

我已经阅读了文档,它有预测功能:http: //scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html

怎么做预测?

python machine-learning scikit-learn

6
推荐指数
1
解决办法
5400
查看次数

标签 统计

machine-learning ×1

python ×1

scikit-learn ×1