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

1 回表示 (過去 30 日間)
Betzalel Fialkoff
Betzalel Fialkoff 2018 年 3 月 25 日
回答済み: Billy Ram 2022 年 3 月 15 日
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 件のコメント
Betzalel Fialkoff
Betzalel Fialkoff 2018 年 3 月 25 日
Im pretty desperate for a solution here, any help would be greatly appreciated.

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

回答 (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 Center および File ExchangeClassification Ensembles についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by