How to resolve the issue of Y must be a column vector?
조회 수: 12 (최근 30일)
이전 댓글 표시
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
Cris LaPierre
2024년 12월 19일
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.
답변 (1개)
Walter Roberson
2024년 12월 19일
편집: Walter Roberson
2024년 12월 19일
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
Walter Roberson
2024년 12월 20일
"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."
참고 항목
카테고리
Help Center 및 File Exchange에서 Classification Ensembles에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!