Logistic regression with logit()
Logistic regression requires another function from statsmodels.formula.api: logit(). It takes the same arguments as ols(): a formula and data argument. You then use .fit() to fit the model to the data.
Here, you'll model how the length of relationship with a customer affects churn.
churn is available.
This exercise is part of the course
Introduction to Regression with statsmodels in Python
Exercise instructions
- Import the
logit()function fromstatsmodels.formula.api. - Fit a logistic regression of
has_churnedversustime_since_first_purchaseusing thechurndataset. Assign tomdl_churn_vs_relationship. - Print the parameters of the fitted model.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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(____)