stepwiselm() function is not taking the last column of table as Response variable

5 Ansichten (letzte 30 Tage)
I have imported a table with size 2000*85. Table name is data2000.
when I use the command m1 = stepwiselm(dataset2000), it is giving me the following error.
/*
m1 = stepwiselm(data2000)
Error using classreg.regr.FormulaProcessor (line 298)
Cannot determine the response variable.
Error in classreg.regr.LinearFormula (line 48)
f = f@classreg.regr.FormulaProcessor(varargin{:});
Error in classreg.regr.TermsRegression/createFormula (line 857)
formula =
classreg.regr.LinearFormula(modelDef,varNames,responseVar,intercept,link);
Error in LinearModel/createFormula (line 880)
formula = classreg.regr.TermsRegression.createFormula(supplied,modelDef, ...
Error in LinearModel.stepwise (line 70)
start = LinearModel.createFormula(supplied,start,X, ...
Error in stepwiselm (line 100)
model = LinearModel.stepwise(X,varargin{:});
*/
Then I tried the command
m1 = stepwiselm(data2000,Label) and getting the following error
/*
Undefined function or variable 'Label'.*/
Please help. I have attached screenshot as reference.
Thanks in advance

Antworten (1)

Ive J
Ive J am 6 Sep. 2021
The issue stems from variable Timestamp, which is of class datetime. You need to first convert it to numeric type:
data = readtable('data2000.xlsx', 'TextType', 'string');
data.Timestamp = datenum(data.Timestamp);
Also I see you have some string variables, better to include them as categorical when calling the function:
model = stepwiselm(data, 'CategoricalVars', ...);
  1 Kommentar
Pavithra Naik
Pavithra Naik am 9 Sep. 2021
Hi Ive,
I converted Timestamp to numeric type using the instructions you suggested and then tried developing the model . It is working properly now. Thank you very much for helping. I was really stuck and your suggestion helped me to proceed further.
Thanks again.
Commands I used are :
data = readtable('data2000.xlsx', 'TextType', 'string');
data.Timestamp = datenum(data.Timestamp);
model1 = stepwiselm(data);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by