找到精度找到了暗号为3的阵列。预计估计员<=2

2024-04-20 04:04:06 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我应该怎么做来修复这个错误?你知道吗

谢谢。你知道吗


Tags: 数据代码testdatamodel错误scikitlearn
2条回答

我猜,你预测了三节课。它给你三维数组,每个类的概率。你知道吗

尝试这样做:

model = SVC(kernel='poly', max_iter=10,probability=False,class_weight='balanced')

当我把cᴏʟᴅsᴘᴇᴇᴅ的建议应用到我的另一个问题here时,代码起作用了:

model.score(np.reshape(testFeat, (-1, 9 * 6)), testLabels)

相关问题 更多 >