[英]Automatically drop variables with p-value greater than 5% from linear regression model
我想从我的线性回归模型中删除变量(使用循环)。
import statsmodels.api as sm
train_x = sm.add_constant(train_x)
lm = sm.OLS(train_y,train_x).fit()
# Filter only those with a P-value less than 5% - this will be a pandas series
keep_pvals = lm.pvalues[lm.pvalues <= .005]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.