【发布时间】:2016-07-21 15:47:55
【问题描述】:
我正在尝试为我在网上找到的数据集实现 SVM。 features_test、features_train、labels_test、labels_train 是元组的 python 列表。我做了以下将其转换为 numpy 数组。但是 clf.fit 给了我以下错误。
File "ebola.py", line 47, in <module>
clf.fit(features_train_numpy,labels_train_numpy)
File "/usr/lib64/python2.7/site-packages/sklearn/svm/base.py", line 151, in fit
y = self._validate_targets(y)
File "/usr/lib64/python2.7/site-packages/sklearn/svm/base.py", line 514, in _validate_targets
y_ = column_or_1d(y, warn=True)
File "/usr/lib64/python2.7/site-packages/sklearn/utils/validation.py", line 551, in column_or_1d
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (2923, 9)
代码如下
features_train_numpy = np.asarray(features_train)
labels_train_numpy= np.asarray(labels_train)
features_test_numpy = np.asarray(features_test)
labels_test_numpy= np.asarray(labels_test)
from sklearn.svm import SVC
temp = 100
clf=SVC(C=temp,kernel="rbf")
clf.fit(features_train_numpy,labels_train_numpy)`
【问题讨论】:
-
每个数组的形状是什么?通过
print XXX.shape? -
这段代码给了我下面的错误 Traceback (最近一次调用最后一次): File "ebola.py", line 58, in
print np.ndarray.shape(features_train_numpy) TypeError: ' getset_descriptor' object is not callable 代码是这个 features_train_numpy = np.asarray(features_train) labels_train_numpy= np.asarray(labels_train) features_test_numpy = np.asarray(features_test) labels_test_numpy= np.asarray(labels_test) print np.ndarray.shape(features_train_numpy ) -
对不起我的评论风格,首先我是新来的,其次,我在评论中为 cpdes 和错误提供了 4 个空格,但它没有用
标签: python-2.7 numpy machine-learning scikit-learn svm