Failed to Call Classification Learner's Testing Function

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.

11 件のコメント

Walter Roberson
Walter Roberson 2016 年 1 月 21 日
What is the data type of featureVector4 ?
The error message is saying that something is being indexed with a value that is a cell array.
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 1 月 21 日
A 1 x 64 matrix.
Walter Roberson
Walter Roberson 2016 年 1 月 23 日
That report does not appear to be relevant.
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 1 月 24 日
Before geting featureVector4 data from a loop, i declare that variable as featureVector4 = [].
Is this the reason?
Walter Roberson
Walter Roberson 2016 年 1 月 24 日
No, that should be fine.
Could you show the output of
which -all table
?
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 1 月 24 日
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)
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 1 月 27 日
Hello, is someone know the solution?
Thanks
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 4 月 9 日
Help...help...help... :(
PAVITHRA S
PAVITHRA S 2020 年 3 月 2 日
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 2020 年 4 月 12 日
'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);

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2016 年 4 月 9 日

2 投票

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.

19 件のコメント

Angga Lisdiyanto
Angga Lisdiyanto 2016 年 4 月 9 日
編集済み: Angga Lisdiyanto 2016 年 4 月 9 日
Thanks, but there are error again.
Error using predict (line 84)
Systems of struct class cannot be used with the "predict" command. Convert the system to an identified model first, such as by
using the "idss" command.
Please help me again. :(
Walter Roberson
Walter Roberson 2016 年 4 月 9 日
I am not certain.
I see in http://www.mathworks.com/help/stats/export-classification-model-for-use-with-new-data.html#bu4764j-1 that they use the syntax you had used before, not the one I suggested here, so my suggestion was incorrect. However, I notice the documentation there says
"Supply the data T in same data type as your training data used in the app (table or matrix).
If you supply a table, ensure it contains the same predictor names as your training data. The predictFcn ignores additional variables in tables. Variable formats (e.g. matrix or vector, data type) must match the original training data."
You imported your data from xlsx and your data had at least one non-numeric field, so I suspect that your classifier was trained against a table (which is a MATLAB datatype), and so you will now need to predict against a table . That is, instead of the numeric featurevector you would need a table with field names VarName1, VarName2, and so on.
Try
VarNames = arrayfun(@(N) sprintf('VarName%d',N), 1:512, 'Uniform', 0);
FV_table = array2table( featureVector, 'VariableNames', VarNames);
yfit = predict(trainedClassifier, FV_table)
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 4 月 9 日
Thanks for your help.
But your code is still error :
Please help me again...
Angga Lisdiyanto
Angga Lisdiyanto 2016 年 4 月 9 日
編集済み: Angga Lisdiyanto 2016 年 4 月 9 日
It works!!!! Huurraaayyyy!!!!
Yess yess yes yes yes oh yes hahahahha
It works with this code :
VarNames = arrayfun(@(N) sprintf('VarName%d',N), 1:512, 'Uniform', 0);
FV_table = array2table( featureVector, 'VariableNames', VarNames);
yfit = trainedClassifier.predictFcn(FV_table)
Thank you very much sir. :)
Walter Roberson
Walter Roberson 2016 年 4 月 9 日
Yes, sorry, I copied the wrong prediction line to edit.
Betzalel Fialkoff
Betzalel Fialkoff 2018 年 3 月 24 日
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 2018 年 6 月 28 日
編集済み: Walter Roberson 2020 年 12 月 22 日
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)
Hussein Hasan Mohsen
Hussein Hasan Mohsen 2020 年 7 月 12 日
Please some one help me with this?
Mrutyunjaya Hiremath
Mrutyunjaya Hiremath 2020 年 7 月 12 日
FV_table = array2table(featureVector, 'VariableNames',{'CarbonDioxide', 'CarbonMomoxide'. ...});
Hussein Hasan Mohsen
Hussein Hasan Mohsen 2020 年 7 月 13 日
still giving the same error
VarNames = arrayfun(@(N) sprintf('CarbonDioxide%', 'CarbonMonoxide%', 'Ethane%', 'Ethylene%', 'Hydrogen%', 'Methane%', 'Nitrogen%', 'Oxygen%',N), 6:9, 'Uniform', 0);
FV_table = array2table(featureVector, 'VariableNames',{'CarbonDioxide', 'CarbonMonoxide', 'Ethane', 'Ethylene', 'Hydrogen', 'Methane', 'Nitrogen', 'Oxygen'});
yfit = trainedClassifier.predictFcn(FV_table)
Hussein Hasan Mohsen
Hussein Hasan Mohsen 2020 年 7 月 13 日
its workingggggggggggg by using this fuction
yfit = trainedClassifier.predictFcn(featureVector)
Hussein Hasan Mohsen
Hussein Hasan Mohsen 2020 年 7 月 13 日
can some one help me in how to show the accuarcy of testing data
need code......
Mrutyunjaya Hiremath
Mrutyunjaya Hiremath 2020 年 7 月 16 日
cpVal = classperf(groundTruth,classifierOutput);
fprintf('accuarcy of testing data %f', cpVal.CorrectRate);
Hussein Hasan Mohsen
Hussein Hasan Mohsen 2020 年 12 月 5 日
it show me this error
>> cpVal = classperf(groundTruth,classifierOutput);
fprintf('accuarcy of testing data %f', cpVal.CorrectRate);
Not enough input arguments.
Error in groundTruth (line 289)
this.DataSource = dataSource;
and here is line 289 to 292
this.DataSource = dataSource;
this.LabelDefinitions = vision.internal.labeler.validation.checkLabelDefinitions(labelDefs);
this.LabelData = vision.internal.labeler.validation.checkLabelData(labelData, this.DSource, this.LabelDefinitions);
end
Walter Roberson
Walter Roberson 2020 年 12 月 5 日
Notice that it is reporting a problem inside a function named groundTruth, but that classperf expects its first argument to be a variable which is interpreted as ground truth -- the suggested variable in the documentation for classperf is groundTruth but that is data, not a reference to the function groundTruth
So you need to assign something to groundTruth before you make that call to classperf()
NN
NN 2020 年 12 月 7 日
It worked for me also , thank you so much
NN
NN 2020 年 12 月 7 日
how do i compare this Yfit data with trained data and find the rmse value?Kindly help
Fatma HM
Fatma HM 2020 年 12 月 20 日
NN Did you found the answer? Plz I need it too
刘 相志
刘 相志 2021 年 11 月 29 日
Thank you, bro. it helps me a lot :)

サインインしてコメントする。

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by