如何找到分类器的准确率

发布于 2024-12-28 00:46:43 字数 662 浏览 3 评论 0原文

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

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

I am using the KNN classifier and I found the knnclassify does the classification for me in MATLAB.

code:

Class = knnclassify(TestVec,TrainVec, TrainLabel);

The problem I face now, knnclassify just classifies the points and gives them a value but I would like to find the accuracy of this classification.

I tried something like this:

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

It is giving me this error:

??? 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);

Is there a better method to find the accuracy of a classifier or what corrections should I do to improve my code above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

随梦而飞# 2025-01-04 00:46:43

标签的值应为 0 或 1。

要键入的代码:

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

the values of the labels should be 0 or 1.

the code to type :

cp = classperf(TrainLabel);   
Class = knnclassify(TestVec,TrainVec, TrainLabel);
cp = classperf(TestLabel,Class);
cp.CorrectRate
影子的影子 2025-01-04 00:46:43
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文