在 python 中创建模型时得分错误

score error while creating model in python

我正在使用分类报告来检查准确性和混淆矩阵

我对代码做了一些修改,现在似乎可以工作了

x = np.array([17, 17.083333, 17.166667, 17.25, 17.333333, 17.416667]) 
x = x.reshape(6,1) 
y = [1,0,1,1,0,1] 
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size = 0.20) 
clf = svm.SVC(kernel='linear') 
clf.fit(X_train,y_train) 
pred = clf.predict(X_test) 
score= sk.metrics.accuracy_score(y_test,pred) 
report = sk.metrics.classification_report (y_test, pred, target_names = ['0','1']) 
confusionmatrix = sk.metrics.confusion_matrix(y_test,pred) 

print ("Accuracy_Score: "+str(score))
print ("Classification_Report:\n"+report)
print ("Confusion_Matrix:")
print (confusionmatrix)

输出:

Accuracy_Score: 0.5
Classification_Report:
精确召回 f1 分数支持

      0       0.00      0.00      0.00         1
      1       0.50      1.00      0.67         1

平均/总计 0.25 0.50 0.33 2

Confusion_Matrix:
[[0 1]
[0 1]]

我将输入 "x" 更改为一个 numpy 数组并从 x.reshape 中删除了值,而且你在 clf.predict() 中有一个错字你给了它 "Xtest"必须是 "X_test".

希望对您有所帮助