MATLAB Answers

Failed to Call Classification Learner's Testing Function

134 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.


Show 8 older comments
PAVITHRA S on 2 Mar 2020
i tried the above code to test my trained network(classiification learner app). i am unable to execute the code
VarNames = arrayfun(@(N) sprintf('VarName%d',N), 1:512, 'Uniform', 0);
FV_table = array2table( featureVector, 'VariableNames', VarNames);
yfit = trainedClassifier.predictFcn(FV_table)
can u suggest me a solution to test.
Mrutyunjaya Hiremath
Mrutyunjaya Hiremath on 12 Apr 2020
'testingData.xlsx' contains only 512 colums feature vector of tesing data or matrix of N X 512.
testingData = xlsread('testingData.xlsx');
yFit = trainedClassifier.predictFcn(testingData);

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.


Hussein Hasan Mohsen
Hussein Hasan Mohsen on 13 Jul 2020
its workingggggggggggg by using this fuction
yfit = trainedClassifier.predictFcn(featureVector)
Hussein Hasan Mohsen
Hussein Hasan Mohsen on 13 Jul 2020
can some one help me in how to show the accuarcy of testing data
need code......
Mrutyunjaya Hiremath
Mrutyunjaya Hiremath on 16 Jul 2020
cpVal = classperf(groundTruth,classifierOutput);
fprintf('accuarcy of testing data %f', cpVal.CorrectRate);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!