#hidden_layer_sizes=(50)此處使用1層隱藏層,只有50個神經元,max_iter=10疊代訓練10次mlp =MLPClassifier(hidden_layer_sizes=(50), max_iter=10, alpha=1e-4, solver='sgd', verbose=10, tol=1e-4, random_state=1, learning_rate_init=.1)mlp.fit(X_train, y_train)#畫出16個神經元的權重圖,黑色表示負的權重,越深色表示數值越大,白色表示正的權重,越淺色表示數值越大fig, axes = plt.subplots(4, 4)# use global min / max to ensure all weights are shown on the same scalevmin, vmax = mlp.coefs_[0].min(), mlp.coefs_[0].max()for coef, ax inzip(mlp.coefs_[0].T, axes.ravel()): ax.matshow(coef.reshape(28, 28), cmap=plt.cm.gray, vmin=.5* vmin, vmax=.5* vmax) ax.set_xticks(()) ax.set_yticks(())plt.show()