Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.05 KB | None | 0 0
  1. %Load Data
  2. load fisheriris;
  3. %The variable meas contains measurements on the sepal length, sepal width,
  4. %petal length, and petal width for 150 iris specimens from the
  5. %following three species :
  6. labels = unique(species);
  7. disp(labels);
  8. %Train a Linear Discriminant Analysis (LDA) Classifier
  9. mdl = ClassificationDiscriminant.fit(meas,species);
  10. %Predict Species Using the LDA Model
  11. predicted_species = predict(mdl,meas);
  12. %Compute and Visualize the Confusion Matrix
  13. Conf_Mat = confusionmat(species,predicted_species);
  14. disp(Conf_Mat);
  15. %We can visualize the same using a heat map.
  16. h = heatmap(Conf_Mat);
  17.  
  18.  
  19. confMat=Conf_Mat;
  20. %%% précision
  21.  
  22. for i =1:size(confMat,1)
  23.  
  24.     precision(i)=confMat(i,i)/sum(confMat(:,i));
  25.  
  26. end
  27.  
  28. Precision=sum(precision)/size(confMat,1);
  29. disp(Precision);
  30. %%% recall
  31.  
  32. for i =1:size(confMat,1)
  33.  
  34.     recall(i)=confMat(i,i)/sum(confMat(i,:));
  35.  
  36. end
  37. Recall=sum(recall)/size(confMat,1);
  38. disp(Recall);
  39. %%% F-score
  40.  
  41. F_score=2*Recall*Precision/(Precision+Recall); %%F_score=2*1/((1/Precision)+(1/Recall));
  42. disp(F_score);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement