找到准确性 - 找到具有暗淡的数组3.估计估计值<= 2

时间:2018-02-03 03:11:49

标签: python arrays numpy model scikit-learn

我有以下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.

我该怎么做才能解决此错误?

感谢。

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')