开始使用免费开始使用

绘制混淆矩阵的马赛克图

手动计算性能矩阵也许很有趣,但如果您需要比较多个模型的混淆矩阵,就会变得繁琐。好在 .pred_table() 方法可以直接为您计算混淆矩阵。

此外,您还可以将 .pred_table() 方法的输出传给 mosaic() 函数,将混淆矩阵可视化。

churnmdl_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()
编辑并运行代码