吴恩达的机器学习-识别猫采用一层的神经网络

clc;clear;
close all;

k=50;
nk=40;
rate=0.01;
for i = 1:k
m1=imread(['C:\Users\googol\Documents\MATLAB\MachineLearning\train\test',num2str(i),'.jpg']);
traindata{i}=double(m1); %I{1}表示数组的概念
traindata{i}=traindata{i}/255;
X(:,i)=Fun_Preprocessing(traindata,i);
end

for i = 1:nk
m1=imread(['C:\Users\googol\Documents\MATLAB\MachineLearning\train\notcat',num2str(i),'.jpg']);
traindata{i}=double(m1); %I{1}表示数组的概念
traindata{i}=traindata{i}/255;
X(:,i+k)=Fun_Preprocessing(traindata,i);
end


type=[ones(k,1);zeros(nk,1)]
%%fileInfo =h5info('C:\Users\googol\Documents\MATLAB\MachineLearning\catwu\train_catvnoncat.h5');
X(size(X,1)+1,:)=ones(1,size(X,2));
q=rand(size(X,1),1)/100000;


for i=1:1000000
   z=(q'*X)';
   py=(double(1)./(1+exp(-z)));
   dy=py-type;
   q=q-(rate/(k+nk))*((dy)'*X')';
   df=((dy)'*X')';
    if max(abs(df))<0.1
        break;
    end
end

z=(q'*X)';
py=(double(1)./(1+exp(-z)))
plot(1:(k+nk),py);

testsum=21;
for i = 1:testsum
m1=imread(['C:\Users\googol\Documents\MATLAB\MachineLearning\test\traincat (',num2str(i),').jpg']);
testdata{i}=double(m1); %I{1}表示数组的概念
testdata{i}=testdata{i}/255;
test(:,i)=Fun_Preprocessing(testdata,i);
end

test(size(test,1)+1,:)=ones(1,size(test,2));
testz=(q'*test)';
z=(q'*X)';
testpy=(double(1)./(1+exp(-testz)))
hold on
plot(1:testsum,testpy,'r');

蓝色是训练的结果,红色是测试的结果,效果不太好。

吴恩达的机器学习-识别猫采用一层的神经网络_第1张图片

你可能感兴趣的:(机器人学习)