2012-01-20 5 views
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); 

이 분류의 정확성을 찾을 수있는 더 좋은 방법이 아니면 내가 무엇을 수정해야

나는 이런 식으로 뭔가를 시도 위의 코드를 개선합니까?

+0

그럼, 벡터는'처럼 Class'는 무엇입니까? 그것은 NaN의 음이 아닌 정수의 벡터입니까? –

+0

클래스는 117 x1 행렬입니다. 값은 1 또는 -1 ... 1이고 음수는 -1입니다. – lakesh

+1

'-1'항목을 '0'으로 설정하여 효과가 있는지 확인할 수 있습니까? ? –

답변

1

레이블의 값은 0이어야한다 또는 1

코드를 입력 :

cp = classperf(TrainLabel); 
Class = knnclassify(TestVec,TrainVec, TrainLabel); 
cp = classperf(TestLabel,Class); 
cp.CorrectRate 
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