使用 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(____)