from sklearn.model_selection import train_test_split from sklearn.neural_network import MLPClassifier from sklearn.utils import check_random_state X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size = 0.25, random_state = 2) X_train.shape,X_test.shape,Y_train.shape,Y_test.shape m1p = MLPClassifier(solver = 'lbfgs',hidden_layer_sizes = [200,100], activation = 'relu', alpha = 1,random_state = 62) mlp.fit(X_train,Y_train) print("=============================\n") print('测试数据集得分:{:.2f}%'.format(mlp.score(X_test,Y_test)*100)) print("=============================\n") 修改后的代码
时间: 2023-08-09 13:05:14 浏览: 90
Sklearn.neural_network.MLPRegressor参数思维导图.zip
抱歉,我不是一个可以运行代码的程序,但我可以帮助你理解修改后的代码。根据您的描述,您将原始代码中的变量名 `m1p` 修改为 `mlp`,并且在使用 `MLPClassifier` 的 `fit()` 函数之前,需要将其实例化。因此,修改后的代码应该如下所示:
```
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
from sklearn.utils import check_random_state
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.25, random_state=2)
print(X_train.shape, X_test.shape, Y_train.shape, Y_test.shape)
mlp = MLPClassifier(solver='lbfgs', hidden_layer_sizes=[200, 100], activation='relu', alpha=1, random_state=62)
mlp.fit(X_train, Y_train)
print("=============================\n")
print('测试数据集得分:{:.2f}%'.format(mlp.score(X_test, Y_test)*100))
print("=============================\n")
```
这是一个使用多层感知器(MLP)进行分类的示例代码。在这个例子中,我们使用 `MLPClassifier` 类来实例化一个具有两个隐藏层的神经网络,并使用 `lbfgs` 作为优化算法。我们拆分数据集,将其分为训练集和测试集,然后使用 `fit()` 函数训练模型,并使用 `score()` 函数计算模型在测试集上的得分。
阅读全文