数学之路(3)-机器学习(3)-机器学习算法-神经网络[13]

不用重复造轮子,我们可以直接使用多层感知器的库,目前多层感知器的库较多,我们选择纯python库实现的神经网络库-neurolab,该库基于LGPL协议,下载地址 为:

https://code.google.com/p/neurolab/

我们用这个库训练我们前面的非线性分类的例子

本博客所有内容是原创,未经书面许可,严禁任何形式的转载

http://blog.csdn.net/u010255642


>>> import neurolab as nl

>>> train_x = [[4,11],[7,340],[10,95],[3,29],[7,43],[5,128]]
>>> input=np.array(train_x)

>>> d =[[1],[0],[1],[0],[1],[0]]
>>> target=np.array(d)
>>> target
array([[1],
       [0],
       [1],
       [0],
       [1],
       [0]])
>>> input
array([[  4,  11],
       [  7, 340],
       [ 10,  95],
       [  3,  29],
       [  7,  43],
       [  5, 128]])

>>> net = nl.net.newff([[3, 10], [11, 400]], [5, 1])
>>> err = net.train(input, target, show=15)
Epoch: 15; Error: 0.326594518922;
Epoch: 30; Error: 0.0242485565317;
The goal of learning is reached

训练完毕后,我们验证一下,效果不错
>>> net.sim([[3, 10]])
array([[ 0.99999326]])
>>> net.sim([[9, 80]])
array([[ 0.89054486]])
>>> net.sim([[6.5,272]])
array([[ 0.05707987]])
>>> net.sim([[10,80]])
array([[ 0.9448553]])
>>> net.sim([[5,125]])
array([[ 0.12198103]])
>>> net.sim([[5,100]])
array([[ 0.18880761]])
>>> 

可以设定一个硬限幅函数,以0.5为一个阈值,超过这个阈值返回1,否则返回0


新版Matlab中神经网络训练函数Newff的详细讲解-新版Matlab中神经网络训练函数Newff的使用方法.doc 本帖最后由 小小2008鸟 于 2013-1-15 21:42 编辑 新版Matlab中神经网络训练函数Newff的详细讲解 一、   介绍新版newffSyntax·          net = newff],{TF1 TF2...TFNl}, BTF,BLF,PF,IPF,OPF,DDF) Descriptionnewff],{TF1 TF2...TFNl}, BTF,BLF,PF,IPF,OPF,DDF) takes several arguments PR x Q1 matrix of Q1 sample R-element input vectorsTSN x Q2 matrix of Q2 sample SN-element target vectorsSiSize of ith layer, for N-1 layers, default = [ ]. TFiTransfer function of ith layer. (Default = 'tansig' for hidden layers and 'purelin' for output layer.)BTFBackpropagation network training function BLFBackpropagation weight/bias learning function IPFRow cell array of input processing functions. OPFRow cell array of output processing functions. DDFData divison function ExamplesHere is a problem consisting of inputs P and targets T to be solved with a network.·          P = [0 1 2 3 4 5 6 7 8 9 10];T = [0 1 2 3 4 3 2 1 2 3 4];Here a network is created with one hidden layer of five neurons.·          net = newff;The network is simulated and its output plotted against the targets.·          Y = sim;plotThe network is trained for 50 epochs. Again the network's output is plotted.·          net.trainParam.epochs = 50;net = train;Y = sim; plot 二、   新版newff与旧版newff调用语法对比 Example1比如输入input(6*1000),输出output为(4*1000),那么旧版定义:net=newff,[14,4],{'tansig','purelin'},'trainlm');新版定义:net=newff; Example2比如输入input(6*1000),输出output为(4*1000),那么旧版定义:net=newff,[49,10,4],{'tansig','tansig','tansig'},'traingdx');新版定义:net=newff; 更详细请看word文档 新版Matlab中神经网络训练函数Newff的使用方法.doc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值