logit() を使ったロジスティック回帰
ロジスティック回帰では、statsmodels.formula.api の別の関数である logit() を使います。引数は ols() と同じで、formula と data を指定します。その後、.fit() を使ってデータにモデルを当てはめます。
ここでは、顧客との関係の長さが解約(churn)にどう影響するかをモデル化します。
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(____)