for 循环打印逻辑回归统计摘要 |统计模型

for loop to print logistic regression stats summary | statsmodels

我正在尝试弄清楚如何在 statsmodels 中实现 for 循环以获取逻辑回归的统计摘要(遍历自变量列表)。我可以使用传统方法使其正常工作,但使用 for 循环将使我的生活更容易找到变量之间的重要性。

这是我正在尝试做的事情:

df = pd.read_csv('source/data_cleaning/cleaned_data.csv')

def opportunites():
    dep = ['LEAVER']
    indep = ['AGE', 'S0287', 'T0080', 'SALARY', 'T0329', 'T0333', 'T0159', 'T0165', 'EXPER', 'T0356']
    for i in indep:
        model = smf.logit(dep, i, data = df ).fit()
        print(model.summary(yname="Status Leaver", xname=['Intercept', i ],  
        title='Single Logistic Regression'))
        print()
opportunites()

这是有效的传统方法

def regressMulti2():
    model = smf.logit('LEAVER ~ AGE ', data = df).fit()
    print(model.summary(yname="Status Leaver",
    xname=['Intercept', 'AGE Less than 40 (AGE)'], title='Logistic Regression of Leaver and Age'))
    print()

regressMuti2()

def opportunites():
    indep = ['AGE', 'S0287', 'T0080', 'SALARY', 'T0329', 'T0333', 'T0159', 'T0165', 'EXPER', 'T0356']
    for i in indep:
        model = smf.logit(f'LEAVER ~ {i} ', data = df).fit()
        print(model.summary(
            yname="Status Leaver",
            xname=['Intercept', i],
            title=f'Logistic Regression of Leaver and {i}'
        ))
        print()