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에 할당하세요.- 적합된 모델의 매개변수(parameters)를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# 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(____)