from sklearn.datasets import ? from sklearn.model selection import train_test_split from sklearn.neural network import MLPClassifier import numpy as np digits = load_digits() X=digits.data y=digits.target X train X test,y_train,y_test = ? (X,y,random_state=0) mip = ? (solver ='lbfgs',hidden_layer_sizes=[100,100],activation='relu',random_state=62) mlp.fit(X_train,y_train) print(X_train.shape,y_train.shape,X_test.shape,y_test.shape) print("训练得分: {:.2f}".format(mlp.score(X_train.y_train))) print("测试得分: {:.2f}".format(mlp.score(X_test y_test)))
时间: 2023-12-24 21:06:34 浏览: 84
这段代码存在一些问题,可能会导致运行错误,我来帮你修改一下:
```
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
import numpy as np
digits = load_digits()
X = digits.data
y = digits.target
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
mlp = MLPClassifier(solver ='lbfgs', hidden_layer_sizes=[100,100], activation='relu', random_state=62)
mlp.fit(X_train, y_train)
print(X_train.shape, y_train.shape, X_test.shape, y_test.shape)
print("训练得分: {:.2f}".format(mlp.score(X_train, y_train)))
print("测试得分: {:.2f}".format(mlp.score(X_test, y_test)))
```
修改了以下几个地方:
1. `load_digits` 的拼写错误
2. `train_test_split` 的调用方式错误,应该为 `train_test_split(X, y, random_state=0)`
3. `MLPClassifier` 的调用方式错误,应该为 `MLPClassifier(solver='lbfgs', hidden_layer_sizes=[100,100], activation='relu', random_state=62)`
4. 打印得分时,应该为 `mlp.score(X_train, y_train)` 和 `mlp.score(X_test, y_test)`
阅读全文