로지스틱 회귀 적합도 정량화

Python에서 statsmodels로 살펴보는 회귀 소개

Maarten Van den Broeck

Content Developer at DataCamp

네 가지 결과

예측 음성 예측 양성
실제 음성 정확 거짓 양성
실제 양성 거짓 음성 정확
Python에서 statsmodels로 살펴보는 회귀 소개

혼동 행렬: 결과 개수

actual_response = churn["has_churned"]
predicted_response = np.round(mdl_recency.predict())
outcomes = pd.DataFrame({"actual_response": actual_response,
                         "predicted_response": predicted_response})
print(outcomes.value_counts(sort=False))
actual_response  predicted_response
0                0.0                   141
                 1.0                    59
1                0.0                   111
                 1.0                    89
Python에서 statsmodels로 살펴보는 회귀 소개

혼동 행렬 시각화

conf_matrix = mdl_recency.pred_table()

print(conf_matrix)
[[141.              59.]
 [111.              89.]] 
진짜 음성(TN) 거짓 양성(FP)
거짓 음성(FN) 진짜 양성(TP)
from statsmodels.graphics.mosaicplot
import mosaic

mosaic(conf_matrix)

이탈 여부 대 최신성 모델 결과의 모자이크 플롯. 실제 이탈과 실제 비이탈이 각각 200개여서 각 열의 너비가 같습니다.

Python에서 statsmodels로 살펴보는 회귀 소개

정확도

정확도는 올바른 예측의 비율입니다.

$$ \text{accuracy} = \frac{TN + TP}{TN + FN + FP + TP} $$

 [[141.,  59.],
  [111.,  89.]]
TN = conf_matrix[0,0]
TP = conf_matrix[1,1]
FN = conf_matrix[1,0]
FP = conf_matrix[0,1]
acc = (TN + TP) / (TN + TP + FN + FP)
print(acc)
0.575
Python에서 statsmodels로 살펴보는 회귀 소개

민감도

민감도는 실제 양성 중 올바르게 예측한 비율입니다.

$$ \text{sensitivity} = \frac{TP}{FN + TP} $$

 [[141.,  59.],
  [111.,  89.]]
TN = conf_matrix[0,0]
TP = conf_matrix[1,1]
FN = conf_matrix[1,0]
FP = conf_matrix[0,1]
sens = TP / (FN + TP)
print(sens)
0.445
Python에서 statsmodels로 살펴보는 회귀 소개

특이도

특이도는 실제 음성 중 올바르게 예측한 비율입니다.

$$ \text{specificity} = \frac{TN}{TN + FP} $$

 [[141.,  59.],
  [111.,  89.]]
TN = conf_matrix[0,0]
TP = conf_matrix[1,1]
FN = conf_matrix[1,0]
FP = conf_matrix[0,1]
spec = TN / (TN + FP)
print(spec)
0.705
Python에서 statsmodels로 살펴보는 회귀 소개

Lass uns üben!

Python에서 statsmodels로 살펴보는 회귀 소개

Preparing Video For Download...