모형 추론 해석

Python으로 배우는 Generalized Linear Models

Ita Cirovic Donev

Data Science Consultant

베타 계수 추정

  • 최대우도추정(MLE)
  • 추정 계수 $\hat\beta$
    • 로그우도가 최대가 됨

우도함수

Python으로 배우는 Generalized Linear Models

베타 계수 추정

  • 반복가중최소제곱(IRLS)

적합된 모형의 요약 출력

Python으로 배우는 Generalized Linear Models

유의성 검정

계수 추정 관련 통계를 강조한 적합 모형의 요약 출력.

Python으로 배우는 Generalized Linear Models

표준오차(SE)

  • 봉우리가 완만함
    $\rightarrow$ 최댓값 위치 파악이 어려움
    $\rightarrow$ SE 증가

표준오차가 큰 경우의 우도 시각화.

  • 봉우리가 뚜렷함
    $\rightarrow$ 최댓값 위치가 명확함
    $\rightarrow$ SE 감소

표준오차가 작은 경우의 우도 시각화.

Python으로 배우는 Generalized Linear Models

표준오차 계산

# Extract variance-covariance matrix
print(model_GLM.cov_params())
           Intercept    weight
Intercept   0.774762 -0.325087
weight     -0.325087  0.141903
# Compute standard error for weight
std_error = np.sqrt(0.141903)
0.3767

분산-공분산 행렬

분산-공분산 행렬 일러스트

Python으로 배우는 Generalized Linear Models

유의성 검정

  • z-통계량 $$ \color{#2485F2}{z=\hat\beta/SE} $$

  • $\color{#2485F2}{z}$가 크면 $\Rightarrow$ 계수 $\ne0$ $\Rightarrow$ 변수가 유의함

  • 경험법칙: 기준값 2

예시: 말굽게 모델
y ~ weight

$z = 1.8151/0.377 = 4.819$

Python으로 배우는 Generalized Linear Models

베타의 신뢰구간

  • 추정치의 불확실성
  • $\beta$의 95% 신뢰구간

$$ [\color{#5A5AF3}{하한},\color{#D8498E}{상한}] $$

$$ [\color{#5A5AF3}{\hat\beta - 1.96 \times SE},\color{#D8498E}{\hat\beta+1.96 \times SE}] $$

Python으로 배우는 Generalized Linear Models

신뢰구간 계산

예시: 말굽게 모델

                 coef    std err   
<hr />-------------------------------
Intercept     -3.6947      0.880  
weight         1.8151      0.377  

Python으로 배우는 Generalized Linear Models

신뢰구간 추출

print(model_GLM.conf_int())
                  0         1
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Python으로 배우는 Generalized Linear Models

신뢰구간 추출

print(model_GLM.conf_int())
              lower         1
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Python으로 배우는 Generalized Linear Models

신뢰구간 추출

print(model_GLM.conf_int())
                  0     upper
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Python으로 배우는 Generalized Linear Models

승산(odds) 신뢰구간

  1. $\beta$의 신뢰구간 추출

  2. 양 끝점 지수변환

print(np.exp(model_GLM.conf_int()))
                  0          1
Intercept  0.004428   0.139519
weight     2.935348  12.851533
Python으로 배우는 Generalized Linear Models

연습해 봅시다!

Python으로 배우는 Generalized Linear Models

Preparing Video For Download...