Error using ~= Invalid types for comparison.

조회 수: 3 (최근 30일)
Saraswathi S
Saraswathi S 2021년 6월 29일
댓글: Saraswathi S 2021년 7월 2일
misclassrate = sum(Predicted ~= testdata.N)/numel(Predicted)
Here, my predicted variables are categorical while testdata.N is from a table.
Can anyone say what is the issue here?
  댓글 수: 2
KSSV
KSSV 2021년 6월 29일
Check the class of Predicted and testdata.N....they should be of same to compare.
Saraswathi S
Saraswathi S 2021년 7월 2일
Thank you so much. That was the issue. one was a categorical data and the other double.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 29일
You probably used categorical(traindata.N) when you did the training -- that is, you probably took numeric data and converted it to categorical and used the categorical as the labels.
And how that it is time to validate, you have predicted categorical labels, but your testdata.N is still numeric. You have to convert it to categorical() in order to do the comparison.
misclassrate = sum(Predicted ~= categorical(testdata.N))/numel(Predicted)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Categorical Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by