Error using ~= Invalid types for comparison.

3 visualizaciones (últimos 30 días)
Saraswathi S
Saraswathi S el 29 de Jun. de 2021
Comentada: Saraswathi S el 2 de Jul. de 2021
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 comentarios
KSSV
KSSV el 29 de Jun. de 2021
Check the class of Predicted and testdata.N....they should be of same to compare.
Saraswathi S
Saraswathi S el 2 de Jul. de 2021
Thank you so much. That was the issue. one was a categorical data and the other double.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 29 de Jun. de 2021
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)

Más respuestas (0)

Categorías

Más información sobre Categorical Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by