What is causing the error from matlab predict function? Also, how to format data to use in classifier validation?

1 view (last 30 days)
Using MATLAB 2015a Classification Learner App, I've trained a Cubic SVM model. I'd like to validate a new data point with this model, but on attempt the following error is produced:
Variables have been created in the base workspace.
To use the exported classifier 'trainedClassifier1' to make predictions on new data, T, use
yfit = predict(trainedClassifier1, T{:,trainedClassifier1.PredictorNames})
If your new data contains any integer variables, then preprocess the data to doubles like this:
X = table2array(varfun(@double, T(:,trainedClassifier1.PredictorNames)));
yfit = predict(trainedClassifier1, X)
>> T = featureMatrix(:,7);
>> yfit = predict(trainedClassifier1, T{:,trainedClassifier1.PredictorNames})
Error using numel
Bad subscripting index.
What is causing this error?
Also, my training data was 4629x8, where the eighth column was the label (response). For the new data, the eighth column has been removed, i.e., 433x7, since the label column should not be needed (or in practice is not known). Is this the correct data format?

Answers (2)

Brendan Hamm
Brendan Hamm on 22 May 2015
Given the error it seems that maybe your data contains values which are not doubles (i.e. integers) which need to first be cast to doubles. The error even suggests to you how to do this. If you provide your code this would make it much easier to figure out what is going on, as otherwise I am guessing based on the error.
  2 Comments
John
John on 22 May 2015
Brendan,
My input data was not properly formatted. For my input data, featureMatrix, which had 8 columns where the 8th was class labels, I was using T = featureMatrix(:,7); instead of T = featureMatrix(:,1:7);.
Classification is now working. Thank you.
muhammad
muhammad on 27 Aug 2015
Edited: muhammad on 27 Aug 2015
i am getting the same error .could you please tell me how to figure out this error and do we need to calculate sensitivity, specificity and accuracy manually ? thanks

Sign in to comment.


MEENU SAINI
MEENU SAINI on 10 May 2018
Right ans is here:
https://in.mathworks.com/matlabcentral/answers/289168-using-exported-classifer-model

Community Treasure Hunt

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

Start Hunting!