多层感知机鸢尾花分类python代码
时间: 2023-11-13 16:55:44 浏览: 143
好的,以下是多层感知机鸢尾花分类的 Python 代码:
```python
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neural_network import MLPClassifier
# 加载数据集
iris = load_iris()
X = iris.data
y = iris.target
# 数据集划分
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
# 数据标准化
sc = StandardScaler()
sc.fit(X_train)
X_train_std = sc.transform(X_train)
X_test_std = sc.transform(X_test)
# 多层感知机模型训练
mlp = MLPClassifier(hidden_layer_sizes=(10,), max_iter=1000)
mlp.fit(X_train_std, y_train)
# 模型评估
print('训练集准确率:', mlp.score(X_train_std, y_train))
print('测试集准确率:', mlp.score(X_test_std, y_test))
```
阅读全文