Hello Ashley,
The predict function expects an input classifier of type such as ClassificationKNN or ClassificationTree etc. In this case you are passing a variable T which is if type struct. That is the reason for the error.
Type the following at the command prompt to see the contents of the struct:
Here one of the fields will be the classification object. For e.g. for my exported model referred by struct variable trainedClassifier, I see the following.
>> trainedClassifier
trainedClassifier =
predictFcn: [function_handle]
RequiredVariables: {1x11 cell}
ClassificationKNN: [1x1 ClassificationKNN]
About: 'This struct is a tra…'
HowToPredict: 'To make predictions …'
Note here that one of the fields is the actual classification object, ClassificationKNN. Note that, based on the type of trained classifier this might differ. To access this we can use the dot operator.
kNNMdl = trainedClassifier.ClassificationKNN;
Now use this as input to the predict function to get scores:
[labels,score] = predict(kNNMdl,ValData);
Best Answer