1

我正在使用 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);

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

4

2 回答 2

1

标签的值应为 0 或 1。

要键入的代码:

cp = classperf(TrainLabel);   
Class = knnclassify(TestVec,TrainVec, TrainLabel);
cp = classperf(TestLabel,Class);
cp.CorrectRate
于 2012-01-20T17:22:12.450 回答
0
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-01-12T07:48:18.530 回答