开始使用免费开始使用

可视化多变量

当您开始考虑更多变量时,把它们同时绘制出来会越来越困难。除了用 x 和 y 轴来表示两个数值变量外,您还可以用颜色表示第三个数值变量,并用分面来表示分类变量。但在可解释性变差之前,这基本就是上限了。也有一些专门的图表类型,如相关性热力图和平行坐标图,可以处理更多变量,但它们对每个变量提供的信息更少,而且并不适合可视化模型预测。

在这里,您将把散点图用到极限,在同一幅图中同时展示房价、到 MRT 车站的距离、附近便利店数量以及房龄。

taiwan_real_estate 已提供。

本练习是课程的一部分

Python 中级回归:使用 statsmodels

查看课程

练习说明

  • taiwan_real_estate 中每个 house_age_years 创建一个分面网格。
  • 使用 taiwan_real_estate 数据集,绘制以 sqrt_dist_to_mrt_m 为 x 轴、n_convenience 为 y 轴、并以 price_twd_msq 着色的散点图。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Prepare the grid using taiwan_real_estate, for each house age category, colored by price_twd_msq
grid = ____(data=____,
            col=____,
            hue=____,
            palette="plasma")

# Plot the scatterplots with sqrt_dist_to_mrt_m on the x-axis and n_convenience on the y-axis
grid.map(____,
         ____,
         ____)

# Show the plot (brighter colors mean higher prices)
plt.show()
编辑并运行代码