min_on_training = X_train.min(axis=0) range_on_training = (X_train - min_on_training).max(axis=0) X_train_scaled = (X_train - min_on_training) / range_on_training print(("Minimum for each feature\n", X_train_scaled.min(axis=0))) print(("Maximum for each feature\n", X_train_scaled.max(axis=0))) svc = SVC(gamma='auto') SVC.fit(X_train_scaled, y_train) print("训练集精度:[:.3f]".format(svc.score(X_train_scaled, y_train))) print("训练集精度:[:.3f]".format(svc.score(X_train_scaled, y_test)))修改代码
时间: 2024-01-06 11:11:56 浏览: 124
Front-Training-1-15.zip_The Front
代码中有两处小错误,应该将 `SVC.fit(X_train_scaled, y_train)` 改为 `svc.fit(X_train_scaled, y_train)`,并且在打印训练集精度时,应该将 `[:.3f]` 改为 `{:.3f}`。修改后的代码如下:
```
min_on_training = X_train.min(axis=0)
range_on_training = (X_train - min_on_training).max(axis=0)
X_train_scaled = (X_train - min_on_training) / range_on_training
print("Minimum for each feature:\n", X_train_scaled.min(axis=0))
print("Maximum for each feature:\n", X_train_scaled.max(axis=0))
svc = SVC(gamma='auto')
svc.fit(X_train_scaled, y_train)
print("训练集精度:{:.3f}".format(svc.score(X_train_scaled, y_train)))
print("测试集精度:{:.3f}".format(svc.score(X_test, y_test)))
```
注意,在打印精度时,第二个应该是测试集的精度,所以将 `X_train_scaled` 改成了 `X_test`。
阅读全文