当前位置:   article > 正文

用MLPClassifier分成三类并用矩阵演算演示了一下+用MLPRegressor去证实我的想法_mlpclassifier sequential mlpregressor 关系

mlpclassifier sequential mlpregressor 关系

用MLPClassifier分成三类并用矩阵演算演示了一下

from sklearn.neural_network import MLPClassifier
import numpy as np
X = [[0., 0.], [1., 1.],[3,3]]
y = [0, 1,2]
clf = MLPClassifier(solver='lbfgs', alpha=1e-5,
                    hidden_layer_sizes=(2,),
                    random_state=1, activation='identity')
clf.fit(X, y)

print (clf.predict([[1.2,1]]))



a = np.matrix(clf.coefs_[0])
b = np.matrix(clf.coefs_[1])
theta1 = np.matrix(clf.intercepts_[0])
theta1 = theta1.T
theta2 = np.matrix(clf.intercepts_[1])
theta2 = theta2.T
x=np.matrix([[1.2],[1]])
result = np.exp(b.T * (a.T*x+ theta1)+theta2)
print (result/sum(result))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

用MLPRegressor去证实我的想法!

  • 我证实了输出层的激活函数果然是恒等映射呦呦!
from sklearn.neural_network import MLPRegressor
import numpy as np
X = [[0., 0.], [1., 1.],[3,3]]
y = [0., 1.,2.]
clf = MLPRegressor(solver='lbfgs', alpha=1e-5,tol = 1e-6,
                    hidden_layer_sizes=(2,),
                    random_state=1, activation='identity')
clf.fit(X, y)

print (clf.predict([[3,3]]))



a = np.matrix(clf.coefs_[0])
b = np.matrix(clf.coefs_[1])
theta1 = np.matrix(clf.intercepts_[0])
theta1 = theta1.T
theta2 = np.matrix(clf.intercepts_[1])
theta2 = theta2.T
x=np.matrix([[3.],[3.]])
result = b.T * (a.T*x+ theta1)+theta2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 上面的predict的结果和我写的result是一样的!
  • 真是太神奇啦!
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/747233
推荐阅读
相关标签
  

闽ICP备14008679号