【发布时间】:2020-09-21 10:31:03
【问题描述】:
我是机器学习的新手,我对 sklearn 关于如何在使用sklearn.svm.SVC 时获得分数的文档感到有些困惑。
这是我的代码
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.30)
for _c in [0.4,0.6,0.8,1.0,1.2,1.4]:
svm=SVC(C=_c,kernel='linear')
svm.fit(x_train,y_train)
result=svm.predict(x_test)
print('C value is {} and score is {}'.format(_c,svm.score(x_test,y_test)))
这是输出
C value is 0.4 and score is 0.0091324200913242
C value is 0.6 and score is 0.0091324200913242
C value is 0.8 and score is 0.0091324200913242
C value is 1.0 and score is 0.0091324200913242
C value is 1.2 and score is 0.0091324200913242
C value is 1.4 and score is 0.0091324200913242
我看到所有分数都是一样的,我的问题是如何确定我的模型的最佳分数?
-
我应该将预测值传递给 svm.score y 值,即
result=svm.predict(x_test) svm.score(x_test,result)) -
我是否应该通过 x_test 和 y_test 值,即
svm.score(x_test,y_test))
【问题讨论】:
-
你没有在循环中改变 SVC 的
c参数,它总是 0.6,这就是为什么你总是得到相同的分数 -
请看我编辑的问题,我已经按照你的指出改了,但我的结果仍然没有改变
标签: machine-learning svm cross-validation