Lojistik regresyon uyumunu ölçme

Python ile statsmodels kullanarak Regresyona Giriş

Maarten Van den Broeck

Content Developer at DataCamp

Dört olası sonuç

tahmin: yanlış tahmin: doğru
gerçek: yanlış doğru yanlış pozitif
gerçek: doğru yanlış negatif doğru
Python ile statsmodels kullanarak Regresyona Giriş

Karmaşıklık matrisi: sonuç sayımları

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 ile statsmodels kullanarak Regresyona Giriş

Karmaşıklık matrisini görselleştirme

conf_matrix = mdl_recency.pred_table()

print(conf_matrix)
[[141.              59.]
 [111.              89.]] 
gerçek negatif yanlış pozitif
yanlış negatif gerçek pozitif
from statsmodels.graphics.mosaicplot
import mosaic

mosaic(conf_matrix)

Terk vs. son satın alma zamanına göre model sonuçlarının mozaik grafiği. Gerçek terkler ve gerçek terk etmeyenler için 200'er gözlem vardır, bu yüzden her sütun aynı genişliktedir.

Python ile statsmodels kullanarak Regresyona Giriş

Doğruluk

Doğruluk (accuracy), doğru tahminlerin oranıdır.

$$ \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 ile statsmodels kullanarak Regresyona Giriş

Duyarlılık

Duyarlılık (sensitivity), gerçek pozitiflerin oranıdır.

$$ \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 ile statsmodels kullanarak Regresyona Giriş

Seçicilik

Seçicilik (specificity), gerçek negatiflerin oranıdır.

$$ \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 ile statsmodels kullanarak Regresyona Giriş

Ayo berlatih!

Python ile statsmodels kullanarak Regresyona Giriş

Preparing Video For Download...