Introduction à la régression avec statsmodels en Python
Maarten Van den Broeck
Content Developer at DataCamp
| as_churned | time_since_first_purchase | time_since_last_purchase |
|---|---|---|
| 0 | 0,3993247 | -0,5158691 |
| 1 | -0,4297957 | 0,6780654 |
| 0 | 3,7383122 | 0,4082544 |
| 0 | 0,6032289 | -0,6990435 |
| ... | ... | ... |
| réponse | durée de la relation | récence de l’activité |
mdl_churn_vs_recency_lm = ols("has_churned ~ time_since_last_purchase",
data=churn).fit()
print(mdl_churn_vs_recency_lm.params)
Intercept 0.490780
time_since_last_purchase 0.063783
dtype: float64
intercept, slope = mdl_churn_vs_recency_lm.params
sns.scatterplot(x="time_since_last_purchase", y="has_churned", data=churn)plt.axline(xy1=(0, intercept), slope=slope) plt.show()

sns.scatterplot(x="time_since_last_purchase", y="has_churned", data=churn) plt.axline(xy1=(0,intercept), slope=slope)plt.xlim(-10, 10) plt.ylim(-0.2, 1.2)plt.show()

from statsmodels.formula.api import logit mdl_churn_vs_recency_logit = logit("has_churned ~ time_since_last_purchase", data=churn).fit()print(mdl_churn_vs_recency_logit.params)
Intercept -0.035019
time_since_last_purchase 0.269215
dtype: float64
sns.regplot(x="time_since_last_purchase",
y="has_churned",
data=churn,
ci=None,
logistic=True)
plt.axline(xy1=(0,intercept),
slope=slope,
color="black")
plt.show()


Introduction à la régression avec statsmodels en Python