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

5 ビュー (過去 30 日間)
Pavithra Naik
Pavithra Naik 2021 年 9 月 2 日
コメント済み: Pavithra Naik 2021 年 9 月 9 日
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 件のコメント
Ive J
Ive J 2021 年 9 月 5 日
Can you upload your data mat file?
Pavithra Naik
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
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
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);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by