svc =SVC(C=1000, gamma='auto') svc.fit(X_train_scaled,y_train) print("训练集精度:[:.3f]".format(svc.score(X_train_scaled, y_train))) print("svc.C",svc.C) print("svc.gamma=",svc.gamma) print('='*20) for c_value in[1,10,100,1000]: svc=SVC(C=c_value,gamma='auto') svc.fit(X_train_scaled,y_train) print('C='c_value) print("Training set score:[:.3f]".format(svc.score(X_train_scaled, y_train))) print("Test set score:[:.3f}".format(svc.score(X_train_scaled, y_test))) print('-'*20) pass修改代码
时间: 2024-02-22 15:57:58 浏览: 160
GA_SVM.zip_MATLAB的GA_SVM_ga 核参数_gamma_ga优化svm_惩罚参数C
5星 · 资源好评率100%
修改后的代码如下:
```
svc = SVC(C=1000, gamma='auto')
svc.fit(X_train_scaled, y_train)
print("训练集精度:{:.3f}".format(svc.score(X_train_scaled, y_train)))
print("svc.C =", svc.C)
print("svc.gamma =", svc.gamma)
print('='*20)
for c_value in [1, 10, 100, 1000]:
svc = SVC(C=c_value, gamma='auto')
svc.fit(X_train_scaled, y_train)
print('C=', c_value)
print("Training set score: {:.3f}".format(svc.score(X_train_scaled, y_train)))
print("Test set score: {:.3f}".format(svc.score(X_test_scaled, y_test)))
print('-'*20)
```
我将代码中的 print 语句中的括号和引号进行了修正,使其符合 Python 语法规范。另外,我还在第二个 for 循环中的测试集精度计算中,将 X_train_scaled 改为 X_test_scaled,使其输出正确的测试集精度。
阅读全文