感知机是一个二分类的线性分类模型。
感知机损失函数:f(x)=sign(wx+b)。
sign函数:当x>=0时值为+1,当x<0时值为-1。
感知机学习过程:设定w,b初始值为0,某个点坐标代入y*(wx+b)值小于等于0时称该点为误分类点,更新w,b值,w:=w+r*y*x,b:=b+r*y(r为学习率)。迭代直到不存在误分类点为止。
感知机学习算法的原始形式
代码实现
# _*_ coding:utf-8 -*_
# Filename:perceptron2_1.py
# Author:Guiyuan Chen
# data:2018/9/5
train_set = [[(3, 3), 1], [(4, 3), 1], [(1, 1), -1]]
w = [0, 0]
b = 0
history = []
if __name__ == "__main__":
for i in range(1000):
for item in train_set:
res = 0
res += item[0][0] * w[0] + item[0][1] * w[1]
res += b
res *= item[1]
if res <= 0:
w[0] += 1 * item[0][0] * item[1]
w[1] += 1 * item[0][1] * item[1]
b += 1 * item[1]
print(w, b)
感知机学习算法的对偶形式
存在的问题:
1、《统计学习方法》中求损失函数时为什么不用考虑1/|||w|这一项?
2、Gram矩阵是怎么计算的,《统计学习方法》例2.2如何计算gram矩阵?
本文仅用于本人学习记录, 具体请参考大佬的感知机总结,非常详细:http://www.hankcs.com/ml/the-perceptron.html