開始使用免費開始

含兩個解釋變數的 Logistic 迴歸

Logistic 迴歸也支援多個解釋變數。若要在 Logistic 迴歸模型中加入多個解釋變數,語法與線性迴歸相同。

在這裡你會以資料集中的兩個解釋變數來擬合顧客流失狀態的模型:顧客關係的長度與最近一次購買的時間,並包含它們的交互作用。

churn 已可使用。

本練習屬於課程

使用 Python 的 statsmodels 進行迴歸分析:中級

檢視課程

練習說明

  • statsmodels.formula.api 匯入 logit() 函式。
  • 以顧客流失狀態 has_churned 為應變數,對顧客關係長度 time_since_first_purchase、最近購買時間 time_since_last_purchase,以及這兩個解釋變數之間的交互作用,擬合一個 Logistic 迴歸。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import logit
____

# Fit a logistic regression of churn status vs. length of relationship, recency, and an interaction
mdl_churn_vs_both_inter = ____

# Print the coefficients
print(mdl_churn_vs_both_inter.params)
編輯並執行程式碼