Borrar filtros
Borrar filtros

How can I use a model exported from classification learner to make a prediction?

5 visualizaciones (últimos 30 días)
So I've trained a model and exported it to my workspace however i get an error when i try to use it to make a prediction. I've tried two forms, one as instructed by matlab, and the 2nd according to this answer
first attempt: my code is
m1.predictFcn(featureVec)
and i get an error
Error using array2table (line 62)
The VariableNames property must contain one name for each variable in the table.
Error in mlearnapp.internal.model.DatasetSpecification>@(x)array2table(x','VariableNames',this.PredictorNames)
Error in mlearnapp.internal.model.DatasetSpecification>@(x)exportableClassifier.predictFcn(predictorExtractionFcn(x)) (line 138)
newExportableClassifier.predictFcn = @(x) exportableClassifier.predictFcn(predictorExtractionFcn(x));
2nd attempt
VarNames = arrayfun(@(N) sprintf('VarName%d',N), 1:4, 'Uniform', 0);
FV_table = array2table( featureVector, 'VariableNames', {'a','b','c','d'});
yfit = m1.predictFcn(featureVector)
and this time the error is
Error using array2table (line 62)
The VariableNames property must contain one name for each variable in the table.
Error in mlearnapp.internal.model.DatasetSpecification>@(x)array2table(x','VariableNames',this.PredictorNames)
Error in mlearnapp.internal.model.DatasetSpecification>@(x)exportableClassifier.predictFcn(predictorExtractionFcn(x)) (line 138)
newExportableClassifier.predictFcn = @(x) exportableClassifier.predictFcn(predictorExtractionFcn(x));

Respuestas (1)

Billy Ram
Billy Ram el 15 de Mzo. de 2022
I might be very late in answering this question. I had the same problem and was looking for answers. Make sure that you don't have the supervised class column in your test data.

Community Treasure Hunt

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

Start Hunting!

Translated by