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

1 次查看(过去 30 天)
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));

回答(1 个)

Billy Ram
Billy Ram 2022-3-15
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.

类别

Help CenterFile Exchange 中查找有关 Classification Ensembles 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by