Matlab Fisherris数据与感知器

Matlab Fisherris数据与感知器,matlab,matlab-figure,Matlab,Matlab Figure,我想将感知器算法应用于Fisherris数据,我尝试了以下代码 function [ ] = Per( ) %PERCEPTON_NN Summary of this function goes here % Detailed explanation goes here %%%%%%%%%%%STEP ONE INPUT DATA PREPERATION %N=3000; load fisheriris tr=50; %traning te=50; %test epochs =150;

我想将感知器算法应用于Fisherris数据,我尝试了以下代码

function [  ] = Per(  )
%PERCEPTON_NN Summary of this function goes here
%   Detailed explanation goes here
%%%%%%%%%%%STEP ONE INPUT DATA PREPERATION
%N=3000;
load fisheriris
tr=50; %traning
te=50; %test
epochs =150;

data=meas;
%N = size(meas,1);
%species=nonomil(species)
%figure,plot(data_shuffeled(1,:),data_shuffeled(2,:),'rx');
%%%%%%%%%%%%%%%%%%%STEP TWO INTIALIZE  WEIGHT
baise=1;
w=[baise; 1 ; 1;1 ; 1];
eta=0.9; %%learning rate
%%%%%%%%%%%%%%%%%%%%%%%% Rosen Blatt learning Algo
for epoch=1 : epochs 
for i=1 : tr
   x=[1;data(i,1);data(i,2);data(i,3);data(i,4)]; % input vector
   N = size(species,i); %desiard output
   y=w'*x; % y=actual output ,w'= transpose w , mmoken y=w.*x 
   %%%%%%%%%%%%%%% Activation function (hardlimit)(step fn)
   y=1*(y>=0)+(-1)*(y<0); % da badl el if 
   %%%%%%%%%%% Error calcualtion %%%%%%%
   err(i)=N-y;
   %%%%%%%%%%%%%% update weight %%%%%%%%%5
   wnew=w+ eta*err(i)*x;
   w=wnew;
end
mse(epoch)=mean(err.^2);
end
%%%%%%%%%%%%%%%%%%%%%%  step four classification (testing) %%%%%%%%%%%%%%%%%%5
hold on
for i=1 : te
    %x=[1;data(i,1);data(i,2),data(i,3);data(i,4)];
     x=[1;data(i,1);data(i,2);data(i,3);data(i,4)]; 
   % d=data_shuffeled(3,i+tr);
    N = size(species,i);
    y=w'*x;
    y=1*(y>=0)+(-1)*(y<0);
    if (y==1)
        plot(x(2),x(3),x(4),x(5),'rx');
    elseif y==-1
        plot(x(2),x(3),x(4),x(5),'r&');
    end
end
hold off

 if abs(N-y)>1E-6
    testerro=testerro+1;

end
函数[]=Per()
%此函数的感知器摘要如下所示
%这里有详细的解释
%%%%%%%%%%%第一步输入数据预处理
%N=3000;
装载鱼鳞
tr=50;%训练
te=50;%测试
纪元=150;
数据=多边环境协定;
%N=尺寸(平均值,1);
%种类=非OMIL(种类)
%图,绘图(数据(1,:),数据(2,:),'rx');
%%%%%%%%%%%%%%%%%%%第二步初始化重量
百色=1;
w=[百色;1;1;1;1];
预计到达时间=0.9;%%学习率
%%%%%%%%%%%%%%%%%%%%%%%%罗森布拉特学习算法
对于epoch=1:epoch
对于i=1:tr
x=[1;数据(i,1);数据(i,2);数据(i,3);数据(i,4)];%输入向量
N=尺寸(种类,i);%设计输出
y=w'*x;%y=实际输出,w'=转置w,mmoken y=w*x
%%%%%%%%%%%%%%%激活功能(硬限制)(步骤fn)

y=1*(y>=0)+(-1)*(y首先,你知道MATLAB有一种神经网络训练工具叫做

第二,认为数据是你自己的函数。在MATLAB中有一个叫做
randperm
的东西,你应该用它来洗牌你的数据

第三,当可以在MATLAB中使用向量/矩阵时,要避免使用for循环

代替做(用于测试)

你可能想这样做

X = [ones(te,1), data]; %X is [50x5] so each row of X is x'
y = X*w;   %y is [50x1], X is [50x5], w is [5x1]
idx_p1 = y==1; %all the indices of y where y is +1
idx_m1 = y==-1; %all the indicies of y where y is -1

plot(X(idx_p1,1),y(idx_p1),'rx');
plot(X(idx_m1,1),y(idx_m1),'r&');
我不知道你是如何使用
plot
来绘制四维X的,所以上面只绘制了X的第一个特征(列)

此外,训练对我来说似乎很奇怪。首先,我不认为你应该使用N来表示数据矩阵meas的大小和期望的输出。“yhat”或“ybar”是一个更好的名称。而且,如果N是期望的输出,那么为什么它是
size(species,I)
在这里我循环1:50?species是一个[150x1]向量。
size(species,1)=150
。并且
大小(物种,x)
如果x是2到50,那么x将是1。您确定要这样做吗?它不应该是类似于:

yhat = -ones(50,1); %Everything is -1
yhat(strmatch('virginica,species)) = 1; %except virginicas which are +1

这个问题太笼统了。将来,请提供可管理的小代码片段,指出您面临的特定问题,然后准确地指出您想要的是什么-性能改进、错误,诸如此类。但我需要训练Fisherris数据如何使用perceptron训练算法做到这一点HMI有可能我误解了你的评论,但这里是对它们的回应(1)这不是你问题的重演。这是试图用具体的方法来回答你非常广泛的问题,以改进你的代码(2)这确实解决了你的代码和Fisherris数据。我不会把这部分放在关于strmatch的文章中(维吉尼亚,物种)如果不是。(3)神经网络是单层感知机。
yhat = -ones(50,1); %Everything is -1
yhat(strmatch('virginica,species)) = 1; %except virginicas which are +1