Drkcore

26 10 2009 Python machinelearning Tweet

Pythonでパーセプトロン

Machine Learningを読んでいる

ProductName Machine Learning: An Algorithmic Perspective (Chapman & Hall/Crc Machine Learning & Patrtern Recognition)
Stephen Marsland
Chapman & Hall / ¥ 6,459 ()
通常1~3週間以内に発送

numpyでパーセプトロンでORを訓練してみた(なにげにパーセプトロンとかニューラルネットワークの実装は初めてだったりする)。

from numpy import *
inputs = array([[0,0],[0,1],[1,0],[1,1]])
targets = array([[0],[1],[1],[1]])

nIterations = 6
eta = 0.25
nData = shape(inputs)[0]
nIn = shape(inputs)[1]
nOut  = shape(targets)[1]
weights = random.rand(nIn+1,nOut)

inputs = concatenate((inputs,-ones((nData,1))),axis=1)

for i in range(nIterations):
    outputs = where(dot(inputs,weights)>0,1,0)
    weights += eta*dot(transpose(inputs),targets-outputs)
    print "Iter: %d" % i
    print weights

print "Final outputs are:"
print where(dot(inputs,weights)>0,1,0) 

この本は、アルゴリズムに関して説明するのがメインの本らしいので、コードの解説はあんまなくて、詳しくはサンプルコード読めということらしいが、もう少し読んでみないとわからん。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021