使用 logit() 的逻辑回归
逻辑回归需要使用 statsmodels.formula.api 中的另一个函数:logit()。它与 ols() 接收相同的参数:formula 和 data。然后使用 .fit() 将模型拟合到数据。
这里,您将建模客户关系时长如何影响流失。
已提供 churn 数据集。
本练习是课程的一部分
使用 Python 中的 statsmodels 进行回归入门
练习说明
- 从
statsmodels.formula.api导入logit()函数。 - 使用
churn数据集拟合has_churned相对于time_since_first_purchase的逻辑回归。将结果保存为mdl_churn_vs_relationship。 - 打印已拟合模型的参数。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import logit
____
# Fit a logistic regression of churn vs. length of relationship using the churn dataset
mdl_churn_vs_relationship = ____
# Print the parameters of the fitted model
print(____)