Uploaded by Diego Ederson

pc1 problema3

advertisement
Codigo:20180082e
Mendez Ayala diego ederson
Problema 3
clc;clear all; close all;
% data1
csv=csvread("P3data.csv");
data=csv'
% Indices de clases
n1_index = data(3,:) == 1
n2_index = data(3,:) == 2
n3_index = data(3,:) == 3
%newdata=data(:,291:end)
% Clasificacion
tau = 200;
[theta_t1,theta0_t1,err_t1,msg_t1]
=perceptron_promedio_con_offset(tau,data(:,1:290)) % clasificacion
[theta_t2,theta0_t2,err_t2,msg_t2]
=perceptron_promedio_con_offset(tau,data(:,291:end)) % clasificacion
% Ploteo
hx = data(1,:);
ht1 = (-theta0_t1 -theta_t1(1)*data(1,:))./theta_t1(2);
ht2 = (-theta0_t2 -theta_t2(1)*data(1,:))./theta_t2(2);
figure
scatter(data(1,n1_index),data(2,n1_index),'filled','g')
hold on
scatter(data(1,n2_index),data(2,n2_index),'filled','b')
hold on
scatter(data(1,n3_index),data(2,n3_index),'filled','m')
plot(hx,ht1,'b-')
plot(hx,ht2,'r-')
grid on
xlim([-40,40])
ylim([-60,40])
hold off
% Ploteo de error de entrenamiento vs epoca
figure
plot(err_t1,'b-')
hold on
plot(err_t2,'r-')
grid on
xlim([1,21])
ylim([0,1])
legend('t1','t2')
hold off
Download