我有以下Python代码片段,我尝试在某些数据上运行SVC(使用的库是scikit-learn:
(trainFeat, testFeat, trainLabels, testLabels) = train_test_split(
data, data_labels, test_size=0.20, random_state=42)
model = SVC(kernel='poly', max_iter=10,probability=True,class_weight='balanced')
model.fit(np.reshape(trainFeat, (124,-1)), trainLabels)
accuracy = model.score(testFeat, testLabels)
print('Accuracy: {:.2f}%'.format(acc * 100))
但我在accuracy = model.score(testFeat, testLabels)
:
ValueError: Found array with dim 3. Estimator expected <= 2.
我该怎么做才能解决此错误?
感谢。
答案 0 :(得分:2)
当我在其他问题here中应用cᴏʟᴅsᴘᴇᴇᴅ的建议时,代码有效:
model.score(np.reshape(testFeat, (-1, 9 * 6)), testLabels)
答案 1 :(得分:0)
我想,你预测3个班级。它给你三维数组,每个类的概率。
尝试这样做:
model = SVC(kernel='poly', max_iter=10,probability=False,class_weight='balanced')