python实现感知机(perceptron)原型~
来源:互联网 发布:王健林 鲁豫 知乎 编辑:程序博客网 时间:2024/05/27 20:50
初学统计学习,用的李航的《统计学习方法》课本,感觉实在太有意思了,甚至准备读个应用统计的研究生深入一下。
随手把感知机(perceptron)用python实现了一下,用的书上的例题,代码如下:
(顺便一提,csdn插入代码真是神特么难用,动不动就是切断代码片,动不动就是多了一段html代码……)
##writen by seasonix'''Test document:[3, 3] 1[2, 2] 0[1, 1] -1[0, 0] -2[3, 3] -1[2, 2] -2[1, 1] -3RESULTS: at last, w is [1, 1]RESULYS: at last, b is -3'''w = [0, 0]b = 0j=0training_data = [[(3, 3), 1], [(4, 3), 1], [(1, 1), -1]]learning_rate = 1##training data and learning rate are gived as above.##As follows,here is the calculated/verdicted section of the perceptromdef cal(item): global w, b, j ver = 1 j = 0 while j < len(item): verdict = item[j][1] * (w[0] * item[j][0][0] + w[1] * item[j][0][1] + b) if verdict <= 0: ver = -1 break j+=1 return ver##As follows,here is the updated section of the perceptrondef update(item, i): global w, b w[0] = w[0] + learning_rate * item[i][1] * item[i][0][0] w[1] = w[1] + learning_rate * item[i][1] * item[i][0][1] b = b + learning_rate * item[i][1] print(w,b)##As follows,here is the main part of the perceptron.def perceptron(item): global w, b print(w,b) temp=-1 while temp!=b: temp=b if cal(item) <= 0: update(item, j)##def main():##Call the perceptron function to get the results.perceptron(training_data)print("RESULTS: at last, w is ",w)print("RESULTS: at last, b is ",b)
0 1
- python实现感知机(perceptron)原型~
- 感知机(Perceptron)的python实现
- 感知机(Perceptron)
- Perceptron(感知机)
- 【用python实现《统计学习方法》】之感知机(perceptron)
- 统计学习方法笔记1——感知机(perceptron)的Python实现
- 感知机PLA(perceptron)
- 感知机(perceptron)算法与MATLAB实现
- 线性分类模型--感知机(perceptron)
- 多层感知机(Multilayer Perceptron)
- 2 - 感知机(perceptron)
- Perceptron感知机
- perceptron 感知机
- OR perceptron(感知机 )
- 感知机Perceptron
- 感知机perceptron
- 感知机—Perceptron
- 感知机 — Perceptron
- Java经典算法——窃贼问题
- 两个host上的qemu VM使用bridge互通
- 文章标题
- gdb调试-dump
- ps动作储存覆盖原文件的原因
- python实现感知机(perceptron)原型~
- windows平台搭带c++扩展的nodejs环境
- ES7中的异步编程,虽然我ES6还没有学会
- 2017.03.25暑期实习在线笔试
- jquery事件冒泡,阻止事件冒泡
- Spring MVC Josn格式注解
- 自定义View练习(二)二阶贝塞尔曲线
- XE5开发Android程序调用电话相关功能(短信息和电话)
- Java读取配置文件的各种方式