로지스틱 회귀의 동작 방식

Python의 statsmodels로 배우는 중급 회귀

Maarten Van den Broeck

Content Developer at DataCamp

제곱합은 적절하지 않음

np.sum((y_pred - y_actual) ** 2)

y_actual은 항상 0 또는 1입니다.

y_pred는 0과 1 사이입니다.

제곱합보다 더 좋은 지표가 있습니다.

Python의 statsmodels로 배우는 중급 회귀

우도

       y_pred * y_actual
Python의 statsmodels로 배우는 중급 회귀

우도

       y_pred * y_actual + (1 - y_pred) * (1 - y_actual)
Python의 statsmodels로 배우는 중급 회귀

우도

np.sum(y_pred * y_actual + (1 - y_pred) * (1 - y_actual))

y_actual = 1인 경우

y_pred * 1 + (1 - y_pred) * (1 - 1) = y_pred

y_actual = 0인 경우

y_pred * 0 + (1 - y_pred) * (1 - 0) = 1 - y_pred
Python의 statsmodels로 배우는 중급 회귀

로그우도

  • 우도 계산은 매우 작은 수의 합으로 수치 오차가 생길 수 있습니다.
  • 로그우도는 계산이 더 쉽습니다.
log_likelihood = np.log(y_pred) * y_actual + np.log(1 - y_pred) * (1 - y_actual)

두 식은 같은 값을 줍니다.

Python의 statsmodels로 배우는 중급 회귀

음의 로그우도

로그우도 최대화는 음의 로그우도 최소화와 같습니다.

-np.sum(log_likelihoods)
Python의 statsmodels로 배우는 중급 회귀

로지스틱 회귀 알고리즘

def calc_neg_log_likelihood(coeffs)

intercept, slope = coeffs
# More calculation!
from scipy.optimize import minimize

minimize(
  fun=calc_neg_log_likelihood,
  x0=[0, 0]
)
Python의 statsmodels로 배우는 중급 회귀

Lass uns üben!

Python의 statsmodels로 배우는 중급 회귀

Preparing Video For Download...