MATLAB Answers

Not a valid predictor error when trying to predict

13 views (last 30 days)
Or Shem Tov
Or Shem Tov on 20 May 2020
Answered: Aditya Patil on 17 Feb 2021
I've trained a few models using the classification learner, they work perfectly fine when I export them to the workspace.
But when I'm running them using the function generated by the classification learner, they produce this error after trying to predict:
Error using classreg.learning.internal.table2PredictMatrix>makeXMatrix (line 97)
Table variable Market_Cap is not a valid predictor.
Error in classreg.learning.internal.table2PredictMatrix (line 47)
Xout = makeXMatrix(X,CategoricalPredictors,vrange,pnames);
Error in classreg.learning.classif.CompactClassificationEnsemble/score (line 79)
X = classreg.learning.internal.table2PredictMatrix(X,[],[],...
Error in classreg.learning.classif.CompactClassificationEnsemble/predict (line 159)
scores = score(this,X,varargin{:});
Error in trainClassifier4>@(x)predict(classificationEnsemble,x) (line 73)
ensemblePredictFcn = @(x) predict(classificationEnsemble, x);
Error in trainClassifier4>@(x)ensemblePredictFcn(featureSelectionFcn(predictorExtractionFcn(x))) (line 74)
trainedClassifier.predictFcn = @(x) ensemblePredictFcn(featureSelectionFcn(predictorExtractionFcn(x)));
Error in MakePredictions (line 39)
predictions = trainedModel4.predictFcn(T);
I've had a similar error before but was able to fix it by turning one of the variables to categorical, this isn't the case here, market_cap is the right datatype.
Let me say that I've trained models to be with different features, and I have a code like this at the beginning of the file that trains a model if it doesn't exist in the workspace:
%% Train the models
if ~exist('trainedModel')
trainingData = readtable('historical_data_tagged.csv');
trainedModel = trainClassifier(trainingData);
if ~exist('trainedModel2')
trainingData = readtable('historical_data_tagged.csv');
trainedModel2 = trainClassifier2(trainingData);
if ~exist('trainedModel3')
trainingData = readtable('historical_data_tagged.csv');
trainedModel3 = trainClassifier3(trainingData);
if ~exist('trainedModel4')
trainingData = readtable('historical_data_tagged.csv');
trainedModel4 = trainClassifier4(trainingData);

Answers (1)

Aditya Patil
Aditya Patil on 17 Feb 2021
I have brought this issue to the notice of the concerned staff, and it might be fixed in any of the upcoming releases.

Community Treasure Hunt

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

Start Hunting!