from sklearn.datasets import load_wine
from sklearn.model_selection import train_test_split
wine = load_wine( )
x, y = wine.data, wine.target
x_train, x_test, y_train, y_test=train_test_split(x,y,test_size = 0.3, random_state = 0 )
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler().fit(x_train)
x_train = scaler.transform(x_train)
x_test = scaler.transform(x_test)
from sklearn.neural_network import MLPClassifier
model = MLPClassifier(solver="lbfgs", hidden_layer_sizes=(100,))
from sklearn.neural_network import MLPClassifier
model2 = MLPClassifier(solver="lbfgs", hidden_layer_sizes=(100,))
model2.fit(x_train, y_train)
y_predict_on_train = model2.predict(x_train)
y_predict_on_test = model2.predict(x_test)
from sklearn.metrics import accuracy_score
print("训练集合的准确率为:{:.2f}".format(100*accuracy_score(y_train, y_predict_on_train)))
print("测试集合的准确率为:{:.2f}".format(100*accuracy_score(y_test, y_predict_on_test)))
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32