How do I improve my result of KNN classification using confusion matrix?

조회 수: 4 (최근 30일)
youb mr
youb mr 2019년 11월 16일
댓글: Ridwan Alam 2019년 11월 20일
Hello everyone.
I'm trying to classify a data set containing two classes using a Knn classifer.
and would like to evaluate the performance using its confusion matrix. But how can I use it with the KNN classifier?
This is my code of KNN classifer
model=ClassificationKNN.fit(X,Y,'NumNeighbors',9);
[~,result1]=predict(model,x);
  댓글 수: 2
Image Analyst
Image Analyst 2019년 11월 16일
편집: Image Analyst 2019년 11월 16일
You forgot to attach X and Y in a .mat file
save('answers.mat', 'X', 'Y');
Have you tried the "Classification Learner" App on the App tab of the tool ribbon?
You tagged it with image processing. What about this is at all related to image processing???
youb mr
youb mr 2019년 11월 17일
how i can use confusion_matrix in this situation

댓글을 달려면 로그인하십시오.

답변 (1개)

Ridwan Alam
Ridwan Alam 2019년 11월 20일
yhat = predict(model,x);
[C,order] = confusionmat(y,yhat);
Use this help file to understand how to use C and order:
  댓글 수: 2
youb mr
youb mr 2019년 11월 20일
Error using confusionmat (line 98)
G and GHAT need to have same number of rows
Error in knn (line 189)
C = confusionmat(Y,yhat)
Ridwan Alam
Ridwan Alam 2019년 11월 20일
Here, I am assuming you have trained the model with “X” and “Y”, and are testing with “x” and “y”. “X” and “x” are different data, if in matrix format, they should have same number of columns but different row sizes.
“yhat” is the prediction of your model for test data “x” (not “X”). Confusionmat compares “yhat” with the ground truth or labels “y” (not “Y”) for the test data “x”.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by