開始使用免費開始

使用 logit() 的邏輯斯迴歸

邏輯斯迴歸需要使用 statsmodels.formula.api 中的另一個函式:logit()。它與 ols() 接受相同的引數:formuladata。接著用 .fit() 將模型擬合到資料上。

在這裡,你要建立一個模型,說明顧客關係維持的長度如何影響流失。

已提供 churn

本練習屬於課程

使用 Python 中的 statsmodels 進行回歸入門

檢視課程

練習說明

  • statsmodels.formula.api 匯入 logit() 函式。
  • 使用 churn 資料集,對 has_churnedtime_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(____)
編輯並執行程式碼