尝试在数据集上运行KNN时,出现以下错误。你知道吗
错误:使用序列设置数组元素
我的数据是这样显示的:
这是我的数据类型:
f_vector object
label int64
mi_vector object
thermo_op int64
dtype: object
然后我运行knn如下:
train_x = training[['mi_vector','f_vector','thermo_op']]
train_y = training['label']
from sklearn.neighbors import KNeighborsClassifier
neigh = KNeighborsClassifier(n_neighbors=3)
neigh.fit(train_x, train_y)
这是我在运行上述代码时得到的ValueError:
/home/vikaasa/anaconda2/lib/python2.7/site-packages/sklearn/utils/validation.pyc in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
391 # make sure we acually converted to numeric:
392 if dtype_numeric and array.dtype.kind == "O":
--> 393 array = array.astype(np.float64)
394 if not allow_nd and array.ndim >= 3:
395 raise ValueError("Found array with dim %d. %s expected <= 2."
ValueError: setting an array element with a sequence.
这对我来说似乎是一个直截了当的问题,但我找不到解决这个问题的方法。。任何帮助都将不胜感激!非常感谢。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐