how to evaluate my result knn code using confusion matrix

11 次查看(过去 30 天)
sir, although I can't replace the old data, I have tried several times to use the App toolbox (ClassificactionLearner) to evaluate the confusion matrix using the old data but I always fail a month ago already. can you help me in this direction through a code to determine this confusion matrix in order to know the well classified data and the badly classified data? thank you for your continued support
attached my code
thank you!!

采纳的回答

Rajeev
Rajeev 2023-1-16
编辑:Rajeev 2023-1-16
There are two requirements for the "confusionmat" function that are not being fullfilled in your matlab script:
  • The type of the input must be vectors or character matrices. Your inputs are of the type double. You can use the "num2str" function to convert the double type to char array. For example
char_test_Coords = num2str(test_Coords)
  • The size of both the character array inputs should be the same. In your script, the length of train_Coords is 120 and the length of test_Coords is 30.
Making the above changes should fix the problem.
  38 个评论
Rajeev
Rajeev 2023-1-30
Upon plotting and observing your dataset, it can be seen that the datapoints that belongs to the same class are not close to each other. It is necessary for them to be in clusters for knn search algorithm to work.
Regardless, if the dataset is passed to the knnsearch function, the results are:
As, you can see, the confusion matrix now shows a lot of error/misclassification as the data is not clustered well.
I have also attached the code for your reference.
merlin toche
merlin toche 2023-1-30
What will I say again beyond thank you, sir @Rajeev receive all my gratitude for your competence and your pedagogy in the transmission of knowledge to us who needed. you have a big heart! unfortunately for me the version R2015a I have fails to read the code you sent. however while waiting to change my R2015a version, can I continue if something still bothers me to turn to you and your team?
a concern please: is it necessary to use a threshold for fault detection with kNN? if yes how to do it?
thank you again and again for all you do for me

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by