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

조회 수: 5 (최근 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
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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by