Backward and Forward stepwise regression?

41 次查看(过去 30 天)
i'm using stepwiselm to find a feature subset. I know the function uses a combination of forward and backward elimination. I need to know how to do only forward and only backward. I thin kit has something to do with the PEnter and PRemove but couldn't figure it out. Also I don't wanna go higher than linear for upepr bound. This is how I've used the function:
mdl = stepwiselm(X,y,'constant','Upper','linear');

回答(1 个)

Manikanta Aditya
Manikanta Aditya 2023-3-17
Hi Azarang,
As per my understanding, you would like to know how to do either forward or backward elimination in stepwise regression.
You can control the direction of selection by setting the Probability to Enter(‘PEnter’) and Probability to Remove(‘PRemove’) values to control the significance level of adding or removing feature respectively.
  • For Forward elimination - You can set larger values for Probability to Remove(‘PRemove’) such as ‘PRemove=1’
mdl = stepwiselm(X,y,constant,Upper,linear,PRemove,1);
  • For Backward elimination - You can set smaller values for Probability to Enter(‘PEnter’)such as ‘PEnter=0.05’
mdl = stepwiselm(X,y,constant,Upper,linear,PEnter,0.05);
This means that only features with a Probability value (p-value) less than 0.05 will be considered for addition, effectively turning off the forward selection step.
Note that if you set both 'PEnter’ and ‘PRemove’ to small values, you may end up with no selected features or all features selected, depending on the significance level and the strength of the relationships between the features and the response variable.
For further reference, to check more about ‘stepwiselm’ function please go through this link:
I hope this resolves the issue you were facing.
  3 个评论
Manikanta Aditya
Manikanta Aditya 2023-3-24
The correct code to perform stepwise regression with forward selection in MATLAB would be:
mdl = stepwiselm(X, y, 'linear', 'Upper', 'linear', 'PEnter', 0.05);
This code will start with a simple linear model and use forward selection to add variables to the model until the stopping criteria (specified by the 'PEnter' parameter) are met. The 'Upper' parameter specifies the maximum number of predictor variables to include in the model.
Thank you for bringing this to my attention, and please let me know if you have any further questions!
azarang asadi
azarang asadi 2023-3-24
I think you are saying it wrong, this is backward not forwad. Forward starts with just a constant (intercept) and then add variables with upper bound linear. I think the correct code is as follows:
mdlForward = stepwiselm(Xtrain,ytrain,'constant','Upper','linear','PEnter',0.05);
mdlBackward = stepwiselm(Xtrain,ytrain,'linear','Upper','linear','PRemove',0.1);

请先登录,再进行评论。

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by