我是Python和机器学习的新手。我想将SVM拟合到训练集上。
from sklearn.model_selection import train_test_splitx_train, x_test, y_train, y_test=train_test_split(x, y, test_size=0.3)clf=SVC(kernel='rbf')clf.fit(x_train,y_train)
然后我得到了一个错误: ValueError: y should be a 1d array, got an array of shape (73584, 15) instead.
x_train.shape, x_test.shape, y_train.shape, y_test.shape
输出:
((73584, 37), (31536, 37), (73584, 15), (31536, 15))
那么我该如何解决这个问题呢?如果有任何建议,我将不胜感激。
y
的形状:
标签y
的示例是:
回答:
SVM的输出是,对于每个数据点,一个类别。因此,对于73584个数据点,每个有37个特征,你的目标需要是一个包含73584个分类的向量,每个分类是一个类别编号。你是否对输出进行了独热编码?如果是,你应该撤销这一操作。