在使用机器学习的K近邻算法中,使用到了 sklearn库中的KNeighborsClassifier()
在后面后面跑下面这个代码的时候会报错
NotFittedError: This KNeighborsClassifier instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.
accuracy = clf.score(iris_x_test,iris_y_test)
print("预估概率为{:.0%}".format(accuracy))
解决方法:
使用
import numpy as np