以馬賽克圖呈現混淆矩陣
手動計算效能矩陣也許有趣,但如果你需要比較多個模型、各自建立混淆矩陣,就會變得繁瑣。還好 .pred_table() 方法可以直接幫你算出混淆矩陣。
此外,你也可以把 .pred_table() 的輸出拿來視覺化,用 mosaic() 函式繪製混淆矩陣。
churn 與 mdl_churn_vs_relationship 已可使用。
本練習屬於課程
使用 Python 中的 statsmodels 進行回歸入門
練習說明
- 從
statsmodels.graphics.mosaicplot匯入mosaic()函式。 - 使用
.pred_table()方法建立conf_matrix並列印結果。 - 繪製混淆矩陣的馬賽克圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import mosaic from statsmodels.graphics.mosaicplot
____
# Calculate the confusion matrix conf_matrix
conf_matrix = ____
# Print it
print(conf_matrix)
# Draw a mosaic plot of conf_matrix
____
plt.show()