You must pass class labels as vector

5 Comments

hi guys i can't make the variable correct for the knn algorithm, but when i try with 2 class it worked.
What is size(tlatih)? Also what class() is it?
the size of (tlatih) is consist of (cardboard_feature,...) and (cardboard_feature = zeros(filequantity,3))
This is the code for the image processing method
the code works well when variable (clatih) only consist of (cardboard_feature and glass_feature),but when i add another class the error appear.

Sign in to comment.

Answers (3)

The second parameter to fitcknn must be a vector (of various data types) with the one exception being that it can be a cell array of character vectors. It cannot be a numeric array with three columns.
Your clatih and tlatih contain exactly the same thing. Your clatih should be built from the _target variables.

3 Comments

i see, so how would you recommend me to change the code for example?
oh btw the first picture tlatih should be consist of (cardboard_target,...) not (cardboard_feature) but the result still the same
It is difficult to debug code that we cannot see.
For debugging purposes you should show us the output of
whos tlatih

Sign in to comment.

this is the (tlatih)

1 Comment

That appears to be a cell array of categorical, you should cell2mat to get a vector of categorical

Sign in to comment.

ok i will try that, thankyou for the suggestion.

Asked:

on 2 Jun 2022

Answered:

on 3 Jun 2022

Community Treasure Hunt

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

Start Hunting!