stepwiselm() function is not taking the last column of table as Response variable
2 次查看(过去 30 天)
显示 更早的评论
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
2 个评论
Pavithra Naik
2021-9-6
Hello, This is not a mat file It is excel data. I am uploading the file for your reference
Thank you
回答(1 个)
Ive J
2021-9-6
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 个评论
Pavithra Naik
2021-9-9
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);
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!