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

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

Ive J
Ive J il 6 Set 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 Commento
Pavithra Naik
Pavithra Naik il 9 Set 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);

Accedi per commentare.

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by