csci5521/perceptron/runpercep.m

38 lines
876 B
Mathematica
Raw Permalink Normal View History

2023-09-13 23:43:30 +00:00
% CSCI 5521 Introduction to Machine Learning
% Rui Kuang
% Run perceptron on random data points in two classes
2023-10-01 23:09:50 +00:00
% n = 200; %set the number of data points
% mydata = rand(n,2);
%
% shiftidx = abs(mydata(:,1)-mydata(:,2))>0.00005;
% mydata = mydata(shiftidx,:);
% myclasses = mydata(:,1)>mydata(:,2); % labels
% n = size(mydata,1);
% X = [mydata ones(1,n)']'; Y=myclasses;
% Y = Y * 2 -1;
%
% % init weigth vector
% %%% w = [mean(mydata) 0]';
% w = [1 0 0];
2023-09-13 23:43:30 +00:00
for i = 1:1
2023-10-01 23:09:50 +00:00
%%% w=rand(1,3)'
w = [0.6842
0.5148
0]
w(3,1)=0%go through the origin for visualization
2023-09-13 23:43:30 +00:00
% call perceptron
wtag=perceptron(X,Y,w,10);
end
% call perceptron
% wtag=perceptron(X,Y,w);
% predict
ytag=wtag'*X;
% plot prediction over origianl data
%plot(X(1,ytag<0),X(2,ytag<0),'bo')
%plot(X(1,ytag>0),X(2,ytag>0),'ro')
%legend('class -1','class +1','pred -1','pred +1')