Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I am trying to solve the following question in Matlab. Assume a new iris sample S has a feature vector of [5.0000, 3.5000, 1.4600,

Hi, I am trying to solve the following question in Matlab.

Assume a new iris sample S has a feature vector of [5.0000, 3.5000, 1.4600, 0.2540]. Calculate the distances between the new sample and the 150 samples in the iris dataset using the distance functions. Calculate Mahalanobis distances and plot the obtained distances

I did the following code, but for some reason its not working, can you please help?

load iris.mat feat_S=[5,3.50,1.460,0.2540]; Nsp = length(label); P =cov(feat); Dlist=[];

for i = 1:Nsp feat_i = feat(i, :); m_dist = mahal_distance(feat_S, feat_i,P); mahal_distance = (feat_S-feati) * P * (feat_S-feat_i)'; Dlist(i) = m_dist; end

figure; plot(Dlist); xlabel('Samples in each class') ylabel('Euclidean Distance'); title('Distance between Sample S and the Samples in Iris Dataset');

figure; c = unique(label);

for ic = c' idx= find(label==ic); Dvec = Dlist(idx); if ic==1; plot(Dvec, 'r'); end if ic==2; plot(Dvec, 'k'); end if ic==3; plot(Dvec, 'g'); end hold on; end

xlabel('Samples in each class'); ylabel('Distance of Sample S to Samples of each class'); legend('Class 1', 'Class 2', 'Class 3');

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

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions

Question

Evaluate the importance of diversity in the workforce.

Answered: 1 week ago

Question

Identify the legal standards of the recruitment process.

Answered: 1 week ago