Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert THE CODE BELOW to a 3-class classifier (or rewrite it in Python in the same style level of abstraction) for the Iris dataset. Decide

Convert THE CODE BELOW to a 3-class classifier (or rewrite it in Python in the same style level of abstraction) for the Iris dataset. Decide the best subset of 2-variables for the classification task.

 close all clear load fisheriris ntr=75; nts = size(meas,1) - ntr; %rand('seed',12345) rp=randperm(150); usevars = [1, 2]; predvar = 4; trainx=[ones(ntr,1) meas(rp(1:ntr),usevars)]; trainr=meas(rp(1:ntr),predvar); testx=[ones(nts,1) meas(rp(ntr+1:150),usevars)]; testr=meas(rp(ntr+1:150),predvar); H=50; I=size(trainx,2); w=rand(H,I)*0.2-0.1; v=rand(1,H+1)*0.02-0.01; v(1)=mean(trainr); Nepochs=1000; MSEtrain = zeros(1,Nepochs); MSEtest = zeros(1,Nepochs); lr = 0.01; for epoch = 1:Nepochs %dw = zeros(size(w)); for t = randperm(ntr) x = trainx(t,:)'; z = logsig(w*x); z = [1; z]; y = v * z; r = trainr(t); dv = (r-y)*z'; for h = 2:H+1 for i = 1 : I dw(h-1,i) = (r - y) * v(h) * z(h)*(1-z(h)) * x(i); end end v = v + lr*dv; w = w + lr*dw; % MSEtrain(epoch) = MSEtrain(epoch) + (r - y).^2; end for t = 1:ntr x = trainx(t,:)'; z = logsig(w*x); z = [1; z]; ytest = v * z; MSEtrain(epoch) = MSEtrain(epoch) + ((trainr(t) - ytest).^2); end for t = 1:nts x = testx(t,:)'; z = logsig(w*x); z = [1; z]; ytest = v * z; MSEtest(epoch) = MSEtest(epoch) + ((testr(t) - ytest).^2); end end MSEtrain = MSEtrain / ntr; MSEtest = MSEtest / nts; MSEdummy = mean((testr-mean(trainr)).^2); plot(MSEtrain,'b'), hold on plot(MSEtest,'r'), plot([1 Nepochs],[MSEdummy MSEdummy])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions