我有工作使用支持向量机(SVM)为数据集KDD 99建模。 这是我尝试的代码:
from sklearn.model_selection import train_test_split
train,test=train_test_split(model,test_size=0.3)
train_x=train.iloc[:,:-1]
train_y=train.iloc[:,-1]
test_x=test.iloc[:,:-1]
test_y=test.iloc[:,-1]
from sklearn.svm import SVC
classifier= SVC()
当我使用此代码时:
classifier.fit(train_x,train_y)
我遇到了这样的错误:
ValueError Traceback (most recent call last)
<ipython-input-15-002fa45b4d55> in <module>()
----> 1 classifier.fit(train_x,train_y)
/usr/local/lib/python2.7/dist-packages/sklearn/svm/base.pyc in fit(self, X, y, sample_weight)
148 order='C', accept_sparse='csr',
149 accept_large_sparse=False)
--> 150 y = self._validate_targets(y)
151
152 sample_weight = np.asarray([]
/usr/local/lib/python2.7/dist-packages/sklearn/svm/base.pyc in _validate_targets(self, y)
517 def _validate_targets(self, y):
518 y_ = column_or_1d(y, warn=True)
--> 519 check_classification_targets(y)
520 cls, y = np.unique(y_, return_inverse=True)
521 self.class_weight_ = compute_class_weight(self.class_weight, cls, y_)
/usr/local/lib/python2.7/dist-packages/sklearn/utils/multiclass.pyc in check_classification_targets(y)
169 if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
170 'multilabel-indicator', 'multilabel-sequences']:
--> 171 raise ValueError("Unknown label type: %r" % y_type)
172
173
ValueError: Unknown label type: 'continuous'
希望任何人都可以帮助我解决此问题。 谢谢:)
答案 0 :(得分:0)
您需要传递分类类标签以使用SVC
进行分类。我认为您现在正在传递实数作为类标签train_y
或test_y
。您的班级标签应为int
或string
。