import numpy as np
from sklearn.neural_network import MLPClassifier
train_x = [[1,1,1,1,0,1,1,0,1,1,0,1,1,1,1],
[0,1,0,0,1,0,0,1,0,0,1,0,0,1,0],
[1,1,1,0,0,1,0,1,0,1,0,0,1,1,1],
[1,1,1,0,0,1,0,1,0,0,0,1,1,1,1],
[1,0,1,1,0,1,1,1,1,0,0,1,0,0,1],
[1,1,1,1,0,0,1,1,1,0,0,1,1,1,1],
[1,1,1,1,0,0,1,1,1,1,0,1,1,1,1],
[1,1,1,0,0,1,0,0,1,0,0,1,0,0,1],
[1,1,1,1,0,1,1,1,1,1,0,1,1,1,1],
[1,1,1,1,0,1,1,1,1,0,0,1,1,1,1],
]
train_y = [0,1,2,3,4,5,6,7,8,9]
text_x =[[1,1,0,1,0,0,1,1,1,1,0,1,1,1,1],
[0,1,0,0,1,0,0,1,0,0,1,0,0,0,0]
]
text_y = [6,1]
mlp = MLPClassifier(max_iter = 10000)
mlp.fit(train_x,train_y)
predict_y=mlp.predict(text_x)
predict_y
from sklearn.neural_network import MLPRegressor
import matplotlib.pyplot as plt
%matplotlib inline
train_x=np.arange(0.1,0.9,0.1).reshape(-1,1)
train_y=np.sin(2*np.pi*train_x).ravel()
text_x=np.arange(0.0,1,0.05).reshape(-1,1)
text_y=np.sin(2*np.pi*text_x).ravel()
RG=MLPRegressor(hidden_layer_sizes=(3),activation='tanh',solver='lbfgs',max_iter=200)
RG=RG.fit(train_x,train_y)
predict_y=RG.predict(text_x)
plt.plot(train_x,train_y,'o')
plt.plot(text_x,text_y,c='yellow')
plt.plot(text_x,predict_y,'x',c='red')
plt.show()
|