How to resolve the issue of Y must be a column vector?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
template = templateTree('MaxNumSplits', 20);
IncMdl = fitcensemble(Xinit, Yinit, 'Method', 'Bag', 'Learners', template);
Given below code is not updating the model. It gives error that Yinc must be a vector. I have checked that Yinc is a vector. Please suggest me how to resolve this issue
code is here
startIdx = incrementSize + 1;
while startIdx <= length(trainLabels)
endIdx = min(startIdx + incrementSize - 1,length(trainLabels));
Xinc = trainFeatures(startIdx:endIdx,:);
Yinc = trainLabels(startIdx:endIdx);
% Ensure Yinc is a column vector and categorical
Yinc = Yinc(:);
if ~iscategorical(Yinc)
Yinc = categorical(Yinc);
end
% Update model incrementally
IncMdl = fit(IncMdl, Xinc, Yinc);
startIdx = endIdx + 1;
end
3 Kommentare
Cris LaPierre
am 19 Dez. 2024
Here is a minimal example that reproduces your error.
load ionosphere
Xinit = X;
Yinit = Y;
trainLabels = unique(Yinit);
trainFeatures = X;
template = templateTree('MaxNumSplits', 20);
IncMdl = fitcensemble(Xinit, Yinit, 'Method', 'Bag', 'Learners', template);
incrementSize = 1;
startIdx = incrementSize + 1;
while startIdx <= length(trainLabels)
endIdx = min(startIdx + incrementSize - 1,length(trainLabels));
Xinc = trainFeatures(startIdx:endIdx,:);
Yinc = trainLabels(startIdx:endIdx);
% Ensure Yinc is a column vector and categorical
Yinc = Yinc(:);
if ~iscategorical(Yinc)
Yinc = categorical(Yinc);
end
% Update model incrementally
IncMdl = fit(IncMdl, Xinc, Yinc);
startIdx = endIdx + 1;
end
When I run which fit I get the following
C:\Program Files\MATLAB\R2024b\toolbox\curvefit\curvefit\fit.m
confirming Walter's suspicion that it is calling fit in the Curve Fitting toolbox.
Antworten (1)
Walter Roberson
am 19 Dez. 2024
Bearbeitet: Walter Roberson
am 19 Dez. 2024
IncMdl = fitcensemble(Xinit, Yinit, 'Method', 'Bag', 'Learners', template);
The result of fitting with method 'bag' is a ClassificationBaggedEnsemble https://www.mathworks.com/help/stats/classreg.learning.classif.classificationbaggedensemble.html
ClassificationBaggedEnsemble do not have any property or object functions named fit so the call
IncMdl = fit(IncMdl, Xinc, Yinc);
Note that there are various models that offer fit() function, including incrementalClassificationLinear ... but bagged ensemble does not offer fit(). None of the models potentially generated by fitcensemble() offer fit()
Once more you are trying to do incremental learning on a fitcensemble object, which is something that cannot be done.
9 Kommentare
Walter Roberson
am 20 Dez. 2024
"incrementalClassificationLinear creates an incrementalClassificationLinear model object, which represents a binary classification linear model for incremental learning."
So incrementalClassificationLinear is inherently two-class.
"For multiclass incremental learning, see incrementalClassificationECOC and incrementalClassificationNaiveBayes."
Siehe auch
Kategorien
Mehr zu Classification Ensembles finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!