How to resolve the issue of Y must be a column vector?

조회 수: 12 (최근 30일)
Aksh Kumar
Aksh Kumar 2024년 12월 19일
댓글: Walter Roberson 2024년 12월 20일
template = templateTree('MaxNumSplits', 20);
IncMdl = fitcensemble(Xinit, Yinit, 'Method', 'Bag', 'Learners', template);
Unrecognized function or variable 'Xinit'.
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
Aksh Kumar
Aksh Kumar 2024년 12월 19일
The complete error message is given below
Error using fit>iFit (line 140)
Y must be a column vector.
Error in fit (line 117)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in SAR_Classification (line 178)
IncMdl = fit(IncMdl, Xinc, Yinc);
The size of data file is 570mb, Please suggest me how to upload it.
Thanks for your kind help.
Cris LaPierre
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
Error using fit>iFit (line 140)
Y must be a column vector.

Error in fit (line 117)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
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
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);
is probably being intepreted as a call to fit from the Curve Fitting Toolbox.
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
Aksh Kumar
Aksh Kumar 2024년 12월 20일
편집: Aksh Kumar 2024년 12월 20일
Thanks. I tried to use this function given below as
IncMdl = incrementalClassificationLinear();
IncMdl = fit(IncMdl, Xinc, Yinc);
error is
Error using incremental.classif.ClassificationModel/addClasses (line 707)
Incremental model must have 2 unique class labels.
I request you to please suggest me incrementalClassification model for multiple classes.
Walter Roberson
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 CenterFile Exchange에서 Classification Ensembles에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by