我有包含单个维度和类标签的数据。我想在上面运行 KNN。
我的数据是这样的
feature Label
0.70436073 1
0.91564351 1
0.9931506 1
2.26418779 0
我做了下面的事情,结果出错了。我从错误中了解到 train 的数据类型无法识别,但我不知道如何修复它。请帮忙
>>> train = [ 0.70436073, 0.91564351, 0.9931506, 2.26418779]
>>> train
[0.70436073, 0.91564351, 0.9931506, 2.26418779]
>>> label = ['1','1','1','0']
>>> from sklearn.neighbors import KNeighborsClassifier
>>> knn = KNeighborsClassifier()
>>> knn.fit(train, label)
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
knn.fit(train, label)
File "C:\Python27\lib\site-packages\sklearn\neighbors\base.py", line 586, in fit
return self._fit(X)
File "C:\Python27\lib\site-packages\sklearn\neighbors\base.py", line 126, in _fit
raise ValueError("data type not understood")
ValueError: data type not understood