SVM:评分测试数据

SVM: Scoring test data

我正在使用 scikit-learn 并想在测试集上评估 SVMpredicition

from sklearn.svm import SVC
import numpy


dataset = numpy.loadtxt("training.txt", delimiter="\t")
X = dataset[:,0:15]
y = dataset[:,15:16]
y = y.ravel()

test_dataset_1 = numpy.loadtxt("test_14-15.txt", delimiter="\t")
X_test_1 = test_dataset_1[:,0:15]
y_test_1 = dataset[:,15:16]
y_test_1 = y_test_1.ravel()

model = SVC(kernel='linear', C=75) 

model.fit(X, y)

score_1 = model.score(X_test_1, y_test_1)

我收到 ValueError:

Found Input variables with inconsistent numbers of samples: [1682, 192]

我的训练集有1682个样本,我的测试集有192个。但是我只是在score-method中使用了测试集。为什么会出现此错误?

改变这个:

y_test_1 = dataset[:,15:16]

对此:

y_test_1 = test_dataset_1[:,15:16]

您正在再次读取y_test_1中的原始训练数据,因此它与X_test_1中的样本数不匹配。