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

10 visualizaciones (últimos 30 días)
Aksh Kumar
Aksh Kumar el 19 de Dic. de 2024
Comentada: Walter Roberson el 20 de Dic. de 2024
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 comentarios
Aksh Kumar
Aksh Kumar el 19 de Dic. de 2024
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 el 19 de Dic. de 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
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.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de Dic. de 2024
Editada: Walter Roberson el 19 de Dic. de 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);
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 comentarios
Aksh Kumar
Aksh Kumar el 20 de Dic. de 2024
Editada: Aksh Kumar el 20 de Dic. de 2024
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 el 20 de Dic. de 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."

Iniciar sesión para comentar.

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by