MATLAB Answers

Failed to Call Classification Learner's Testing Function

76 views (last 30 days)
I was using a Matlab R2015b's Classification Learner Toolbox. I was successful in importing file data and export it into an Export Model, and i got a structure named trainedClassifier.
Import process #1
Import process #2
Training process with PCA implemented & Multi Class SVM (One vs All validation)
trainedClassifier variable generated from ToolBox
fetureVector variable which used for testing
yfit = trainedClassifier.predictFcn(featureVector)
After it, i want to doing a test with a new data with this code (i got this code from here ) :
>> yfit = trainedClassifier.predictFcn(featureVector)
Then i got an error output as a follows :
Function 'subsindex' is not defined for values of class 'cell'.
Error in mlearnapp.internal.model.DatasetSpecification>@(t)t(:,predictorNames) (line 135)
extractPredictorsFromTableFcn = @(t) t(:,predictorNames);
Error in mlearnapp.internal.model.DatasetSpecification>@(x)extractPredictorsFromTableFcn(splitMatricesInTableFcn(convertMatrixToTableFcn(x)))
(line 136)
extractPredictorsFcn = @(x) extractPredictorsFromTableFcn(splitMatricesInTableFcn(convertMatrixToTableFcn(x)));
Error in mlearnapp.internal.model.DatasetSpecification>@(x)exportableClassifier.predictFcn(extractPredictorsFcn(x)) (line 137)
exportableClassifier.predictFcn = @(x) exportableClassifier.predictFcn(extractPredictorsFcn(x));
What is the problem and solutions?
Thanks in advance.

  9 Comments

Show 6 older comments
Angga Lisdiyanto
Angga Lisdiyanto on 24 Jan 2016
Off course.
Import process #1
Import process #2
Training process with PCA implemented & Multi Class SVM (One vs All validation)
trainedClassifier variable generated from ToolBox
fetureVector variable which used for testing
yfit = trainedClassifier.predictFcn(featureVector)

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 9 Apr 2016
You have
yfit = trainedClassifier.predictFcn(featureVector)
and my reading just now suggest that perhaps needs to be
yfit = predict(trainedClassifier, featureVector)
The error message indicates that something is trying to be indexed using a cell array as a subscript, which is a valid indexing method for tables but not an indexing method for a double array.

  7 Comments

Show 4 older comments
Betzalel Fialkoff
Betzalel Fialkoff on 24 Mar 2018
HELP, i've coping the above code, my model has only 4 predictors, but im getting an error. this is my code
VarNames = arrayfun(@(N) sprintf('VarName%d',N), 1:4, 'Uniform', 0);
FV_table = array2table( featureVector, 'VariableNames', VarNames);
yfit = m1.predictFcn(FV_table)
" Error using ' (line 421) Undefined function 'ctranspose' for input arguments of type 'table'."
I need this for an interview in in 12 hours, please help!!!
Anna Gerald
Anna Gerald on 28 Jun 2018
Please help in resolving these errors
Error using classreg.learning.internal.table2PredictMatrix>makeXMatrix (line 96) Table variable VarName1 is not a valid predictor.
Error in classreg.learning.internal.table2PredictMatrix (line 47) Xout = makeXMatrix(X,CategoricalPredictors,vrange,pnames);
Error in classreg.learning.regr.CompactRegressionTree/predict (line 557) X = classreg.learning.internal.table2PredictMatrix(X,[],[],...
Error in mlearnapp.internal.model.coremodel.TrainedRegressionTree>@(x)predict(RegressionTree,x) (line 46) functionHandle = @(x) predict(RegressionTree, x);
Error in mlearnapp.internal.model.transformation.TrainedManualFeatureSelection>@(x)decoratedPredictFunction(featureSelectionFunction(x)) (line 61) functionHandle = @(x) decoratedPredictFunction(featureSelectionFunction(x));
Error in mlearnapp.internal.model.DatasetSpecification>@(x)exportableModel.predictFcn(predictorExtractionFcn(x)) (line 167) newExportableModel.predictFcn = @(x) exportableModel.predictFcn(predictorExtractionFcn(x));
Error in copy (line 3) yfit = trainedModel1.predictFcn(FV_table)

Sign in to comment.

More Answers (1)

naishi feng
naishi feng on 6 Jun 2017
it works!!thanks!!!

  0 Comments

Sign in to comment.

Sign in to answer this question.