可视化三个数值变量
与 3D 图相比,还有一些"平面"的替代方案,更易于解读,不过在制作时需要稍加思考。一个不错的方法是:在散点图中将两个数值型解释变量分别放在 x 轴和 y 轴上,并根据响应变量为点着色。
taiwan_real_estate 已提供。
本练习是课程的一部分
Python 中级回归:使用 statsmodels
练习说明
- 计算到最近 MRT 站的距离的平方根,命名为
sqrt_dist_to_mrt_m。 - 使用
taiwan_real_estate数据集绘制散点图:以sqrt_dist_to_mrt_m为横轴、以附近便利店数量为纵轴,并根据房价对点进行着色。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Transform dist_to_mrt_m to sqrt_dist_to_mrt_m
taiwan_real_estate["sqrt_dist_to_mrt_m"] = ____
# Draw a scatter plot of sqrt_dist_to_mrt_m vs. n_convenience colored by price_twd_msq
____
# Show the plot
plt.show()