Traceback (most recent call last):
File "/home/python/Desktop/桥/knn算法.py", line 137, in <module>
clf = SVC(kernel="rbf", gamma=2947.0517025518097).fit(train_data, labels)
File "/usr/local/lib/python3.5/dist-packages/sklearn/svm/_base.py", line 149, in fit
y = self._validate_targets(y)
File "/usr/local/lib/python3.5/dist-packages/sklearn/svm/_base.py", line 525, in _validate_targets
check_classification_targets(y)
File "/usr/local/lib/python3.5/dist-packages/sklearn/utils/multiclass.py", line 169, in check_classification_targets
raise ValueError("Unknown label type: %r" % y_type)
ValueError: Unknown label type: 'unknown'
Process finished with exit code 1
print(labels.dtype)
输出object,此时SVC.fit()就会报以上错误
#如果标签列要求使用浮点型,fit()会报错,此时可以把数据类型转换成'str'
labels = df.iloc[1:91, 2].astype("str").values
#同样转换成'int'也可以
labels = df.iloc[1:91, 2].astype("int").values