How to define fitcensemble matlab function?

I am using following matlab code with latest MATLAB R2024b software
initIdx = 1:incrementSize;
Xinit = trainFeatures(initIdx,:);
Yinit = trainLabels(initIdx);
disp(size(Xinit));
disp(size(Yinit));
% Train initial batch model using fitcensemble
t = templateTree('MaxNumSplits',20); % You can adjust as needed
Mdl = fitcensemble(Xinit, Yinit, ...
'Method', 'Bag', ...
'NumLearningCycles', 100, ...
'Learners', t, ...
'OOBPrediction', 'on');
% Convert to incremental model
IncMdl = incrementalLearner(Mdl);
it is displaying [the following] error
3048 2
3048 1
Error using classreg.learning.FitTemplate/fillIfNeeded (line 734)
OOBPrediction is not a valid parameter name.
Error in classreg.learning.FitTemplate.make (line 140)
temp = fillIfNeeded(temp,type);
^^^^^^^^^^^^^^^^^^^^^^^
Error in fitensemble (line 363)
temp = classreg.learning.FitTemplate.make(method,'nlearn',nlearn,'learners',learners,varargin{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in fitcensemble (line 215)
this = fitensemble(X, Y, Method, NumLearningCycles, Learners, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mdl = fitcensemble(Xinit, Yinit, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I request you to please suggest me how to resolve this issue.

10 Comments

Abhaya
Abhaya on 18 Dec 2024
Edited: Abhaya on 18 Dec 2024
Hi Aksh,
The error 'OOBPrediction is not a valid parameter name' indicates that MATLAB 'fitcensemble' method does not have any property named 'OOBPrediction'.
You can refer to the following MATLAB documentation on 'fitensenmle' method to check all the supported input arguments.
Feel free to mention if you have any specific requirement.
OOBPrediction is a treebagger parameter
Thank you very much for your suggestion. Now I am using
t = templateTree('MaxNumSplits',20);
Mdl= fitcensemble(Xinit, Yinit,'Method', 'Bag', 'NumLearningCycles', 100, 'Learners', t);
disp(Mdl);
ResponseName: 'Y'
CategoricalPredictors: []
ClassNames: [BARELAND BUILTUP BUSHES PLANT RATOON WATER]
ScoreTransform: 'none'
NumObservations: 3048
NumTrained: 100
Method: 'Bag'
LearnerNames: {'Tree'}
ReasonForTermination: 'Terminated normally after completing the requested number of training cycles.'
FitInfo: []
FitInfoDescription: 'None'
FResample: 1
Replace: 1
UseObsForLearner: [3048×100 logical]
% Convert to incremental model
IncMdl = incrementalLearner(Mdl);
This is giving error as Incorrect number or types of inputs or outputs for function incrementalLearner.
Please suggest me how to resolve this issue.
The error occurs because the MATLAB 'incrementalLearner' function expects a Linear regression model as an input.
The fitcensemble function, used to create ensemble classifiers, does not natively support incremental learning. This means that each time you call fitcensemble(), the ensemble model is rebuilt from scratch rather than adding new learners to an existing ensemble.
Thanks a lot for your kind suggestion and help. May I request you to please provide me an alternative to given below code so that it works smoothely.
% Train initial batch model using fitcensemble
t = templateTree('MaxNumSplits',20); % You can adjust as needed
Mdl = fitcensemble(Xinit, Yinit, 'Method', 'Bag',...
'NumLearningCycles', 100, 'Learners', t);
% Convert to incremental model
IncMdl = incrementalLearner(Mdl);
I would be highly obliged to you.
There is no way to do incremental learning on a fitcensemble model.
Thank you very much for your guidence and help. I am trying to use following model
Mdl = TreeBagger(100, Xinit, Yinit, 'Method', 'classification', 'OOBPrediction', 'on');
% Convert to incremental model
IncMdl = incrementalClassificationEnsemble(Mdl);
but this giving error as
Unrecognized function or variable 'incrementalClassificationEnsemble'.
Please suggest me how fix this error
There is simply no function incrementalClassifictionEnsemble() .
There is no way to convert a classification ensemble to incremental learning.
I would like to request you to please let me know whether this Incremental Classification is different than what you suggested that There is no way to convert a classification ensemble to incremental learning.
Looking forward for your kind suggestion.
TreeBagger() as a function returns a TreeBagger object https://www.mathworks.com/help/stats/treebagger.html
There are no functions to convert TreeBagger objects to incremental learning objects.
The documentation at https://www.mathworks.com/help/stats/incremental-learning-overview.html#mw_b9f908d5-71f7-419a-9f6c-386f264864b9 describes the objects that can be converted to incremental learning.
Notice that TreeBagger() and ClassificationBaggedEnsemble and ClassificationEnsemble and ClassificationPartitionedEnsemble are not on this list.

Sign in to comment.

Answers (0)

Asked:

on 18 Dec 2024

Commented:

on 19 Dec 2024

Community Treasure Hunt

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

Start Hunting!