1.パーセプトロン
パーセプトロンは、分類のためのエレガントな統計学習アルゴリズムです。パーセプトロンは実装が非常に簡単で、オンライン アルゴリズムです。最も重要なのは、線形分離可能な集合に適用すると、数学関数、学習アルゴリズム、およびアルゴリズムの正しさの証明の組み合わせとなることです。
2、Pythonアルゴリズムの実装
import numpy as np
X = np.array([[0, 1, 1], [1, 0, 1], [1, 1, 1], [-1, 1, 1], [1, -1, 1]])
Y = np.array([1, 1, 1, 0, 0])
W = np.zeros(3)
def perceptron(x, w):
return (x @ w >= 0).astype(int)
def train(x, y, w):
for i in range(len(x)):
# 估算感知机
h = perceptron(x[i, :], w)
#误分类
if h != y[i]:
if y[i] == 1:
w += x[i, :]
else:
w -= x[i, :]
return perceptron(x, w)
for i in range(5):
h = train(X, Y, W)
print('w=', W, 'acc=', np.mean(h == Y))
出力結果: