【问题标题】:How to find an accuracy of a classifier如何找到分类器的准确性
【发布时间】:2012-02-14 19:02:43
【问题描述】:

我正在使用 KNN 分类器,我发现 knnclassify 在 MATLAB 中为我进行分类。

代码:

Class = knnclassify(TestVec,TrainVec, TrainLabel);

我现在面临的问题,knnclassify 只是对点进行分类并给它们一个值,但我想找到这个分类的准确性。

我试过这样的:

Class = knnclassify(TestVec,TrainVec, TrainLabel);
cp = classperf(TestLabel,Class);
cp.CorrectRate 

它给了我这个错误:

??? Error using ==> classperf at 149
When the class labels of the CP object are numeric, the output
of the classifier must be all non-negative integers or NaN's.

Error in ==> KNN at 3
cp = classperf(TestLabel,Class);

有没有更好的方法来确定分类器的准确性,或者我应该做哪些更正来改进上面的代码?

【问题讨论】:

  • 那么,矢量Class 是什么样的?是非负整数的 NaN 向量吗?
  • 类是一个 117 x1 矩阵。值是 1 或 -1... 1 表示正数,-1 表示负数
  • 您可以尝试将-1 条目设置为0 看看是否有任何效果?
  • 您的意思是将我的 trainlabel 和 testlabel 值更改为 0 或 1?

标签: matlab knn


【解决方案1】:

标签的值应该是 0 或 1。

要输入的代码:

cp = classperf(TrainLabel);   
Class = knnclassify(TestVec,TrainVec, TrainLabel);
cp = classperf(TestLabel,Class);
cp.CorrectRate

【讨论】:

    【解决方案2】:
    maybe, you can use this code to understand...
    
    sample = [2 12   ;47 18 ;46.7 12]
    training=[46.7 12;45 11 ;46.7 13]
    group = [1;2;1]
    class = knnclassify(sample, training, group)
    
    
    cp = classperf(class,group);%to compare 2 matrix, which is have the same row n column
    cp.CorrectRate*100
    

    【讨论】:

      猜你喜欢
      • 2014-10-21
      • 2020-08-14
      • 2012-11-14
      • 2020-08-01
      • 1970-01-01
      • 2020-07-11
      • 2015-04-14
      • 2019-08-17
      • 2016-06-16
      相关资源
      最近更新 更多