import statsmodels.formula.api as smf
import pandas as pd
def forward_selected(data, response):
"""前向逐步回归算法,源代码来自https://planspace.org/20150423-forward_selection_with_statsmodels/
使用Adjusted R-squared来评判新加的参数是否提高回归中的统计显著性
Linear model designed by forward selection.
Parameters:
-----------
data : pandas DataFrame with all possible predictors and response
response: string, name of response column in data
Returns:
--------
model: an "optimal" fitted statsmodels linear model
with an intercept
selected by forward selection
evaluated by adjusted R-squared
"""
remaining = set(data.columns)
remaining.remove(response)
selected = []
current_score, best_new_score = 0.0, 0.0
while remaining and current_score == best_new_score:
scores_with_candidates = []
for candidate in remaining:
formul
python 回归问题特征筛选
最新推荐文章于 2024-06-06 22:45:33 发布