시작하기무료로 시작하기

계수와 절편 확인하기

로지스틱 회귀 모델이 준비되면, 모델이 타당한지 확인하기 위해 계수를 살펴보는 것이 도움이 됩니다.

적합된 로지스틱 회귀 모델 logreg가 주어졌을 때, coef_ 속성으로 계수를 가져올 수 있어요. 계수의 순서는 모델에 변수를 입력한 순서와 같습니다. 절편은 intercept_ 속성으로 가져올 수 있어요.

이전 연습 문제에서 구축한 로지스틱 회귀 모델은 logreg에 추가되어 이미 적합되어 있습니다.

이 연습은 강의의 일부입니다

Python으로 배우는 예측 분석 입문

강의 보기

연습 안내

  • 로지스틱 회귀 모델의 계수를 리스트 coef에 할당하세요.
  • 로지스틱 회귀 모델의 절편을 변수 intercept에 할당하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Construct a logistic regression model that predicts the target using age, gender_F and time_since_last gift
predictors = ["age","gender_F","time_since_last_gift"]
X = basetable[predictors]
y = basetable[["target"]]
logreg = linear_model.LogisticRegression()
logreg.fit(X, y)

# Assign the coefficients to a list coef
coef = ____.____
for p,c in zip(predictors,list(coef[0])):
    print(p + '\t' + str(c))
    
# Assign the intercept to the variable intercept
intercept = ____.____
print(intercept)
코드 편집 및 실행