我希望仅使用c值得到x轴值的图,例如c = [0.000001,0.00001,0.0001,0.001,0.01,1.0]。
另一方面。我希望显示每个 c 的 y 值。
然后在图中用*或正方形标记(c,y)值。
这是我试过的:
from sklearn.svm import LinearSVC
penalty_param=[]
lin_svm=[]
lin_svm_train=[]
for c in (0.000001,0.00001,0.0001,0.001,0.01,1.0):
penalty_param.append(c)
clf = LinearSVC(C=c)
clf.fit(X_train,y_train)
lin_svm.append(clf.score(X_test,y_test))
lin_svm_train.append(clf.score(X_train,y_train))
fig2, ax2 = plt.subplots()
ax2.set_xslim((0.000001,0.00001,0.0001,0.001,0.01,1.0))
ax2.plot(penalty_param,lin_svm,label='Test accuracy',marker='o')
ax2.plot(penalty_param,lin_svm_train,label='Train accuracy ',marker='*')
ax2.set_xlabel(" C : penalty parameter")
ax2.set_ylabel("Accuracy")
ax2.legend(loc='best')
ax2.set_title(' Linear SVM classifier accuracy in terms of C parameter')
fig2.show()
我的代码出了什么问题?
答案 0 :(得分:0)
ax2.set_xscale(value='log')
我刚添加了这行代码。它允许使x轴刻度以对数方式而不是以线性方式变化