码迷,mamicode.com
首页 > 其他好文 > 详细

ANN:MLP-algorithm

时间:2020-02-14 19:06:34      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:alpha   win   for   nbsp   map   ict   mod   list   att   

 1 from sklearn.neural_network import MLPClassifier
 2 from sklearn.datasets import load_wine
 3 from sklearn.model_selection import train_test_split
 4 wine=load_wine()
 5 X=wine.data[:,:2]
 6 y=wine.target
 7 X_train,X_test,y_train,y_test=train_test_split(X,y,random_state=8)
 8 mlp=MLPClassifier(solver=lbfgs,max_iter=1000)
 9 mlp.fit(X_train,y_train)
10 print("the score of this model:{}".format(mlp.score(X_test,y_test)))
 1 import matplotlib.pyplot as plt
 2 from matplotlib.colors import ListedColormap
 3 import numpy as np
 4 cmap_light=ListedColormap([#FFAAAA,#AAFFAA,#AAAAFF])
 5 cmap_bold=ListedColormap([#FF0000,#00FF00,0000FF])
 6 x_min=X_train[:,0].min()-1
 7 x_max=X_train[:,0].max()+1
 8 y_min=X_train[:,1].min()-1
 9 y_max=X_train[:,1].max()+1
10 xx,yy=np.meshgrid(np.arange(x_min,x_max,.02),
11                   np.arange(y_min,y_max,.02))
12 z=mlp.predict(np.c_[xx.ravel(),yy.ravel()])
13 z=z.reshape(xx.shape)
14 plt.figure()
15 plt.pcolormesh(xx,yy,z,cmap=cmap_light)
16 plt.scatter(X[:,0],X[:,1],c=y,edgecolors=k,s=60)
17 plt.xlim(xx.min(),xx.max())
18 plt.ylim(yy.min(),yy.max())
19 plt.title("MLPClassifier:solver=lbfgs")
20 plt.show()
1 mlp=MLPClassifier(solver=lbfgs,max_iter=10000,hidden_layer_sizes=[10,10],activation=tanh,alpha=1)
2 mlp.fit(X_train,y_train)
3 print(mlp.score(X_test,y_test))
1 z=mlp.predict(np.c_[xx.ravel(),yy.ravel()])
2 z=z.reshape(xx.shape)
3 plt.figure()
4 plt.pcolormesh(xx,yy,z,cmap=cmap_light)
5 plt.scatter(X[:,0],X[:,1],c=y,edgecolors=k,s=60)
6 plt.xlim(xx.min(),xx.max())
7 plt.ylim(yy.min(),yy.max())
8 plt.title("MLPClassifier:solver=lbfgs")
9 plt.show()

 

ANN:MLP-algorithm

标签:alpha   win   for   nbsp   map   ict   mod   list   att   

原文地址:https://www.cnblogs.com/St-Lovaer/p/12308352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!