开始使用免费开始使用

90%、95% 和 99% 区间

您是一家位于阿拉斯加费尔班克斯的户外探险公司的数据科学家。近期,客户受到 SO2 污染的影响,导致大量昂贵的取消。公司配备了 CO、NO2 和 O3 的传感器,但没有 SO2 的传感器。

您已构建了一个模型,根据已有传感器的污染物数值来预测 SO2 的水平(已加载为 pollution_model,一个 statsmodels 对象)。您希望研究哪个污染物的数值对模型预测的 SO2 影响最大。这将帮助您在规划户外行程时重点关注相应的污染物。为在报告中提供尽可能多的信息,请为模型估计展示多个不确定性水平。

本练习是课程的一部分

用 Python 提升数据可视化

查看课程

练习说明

  • 根据 alpha 列表中的取值,填写相应的区间宽度百分比(从 90%、95% 和 99% 中选择)。
  • 在 for 循环中,使用分配的 color 为区间着色。
  • 将循环中的 width 百分比值传递给 plt.hlines(),用于在图例中标注。

交互式实操练习

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

# Add interval percent widths
alphas = [     0.01,  0.05,   0.1] 
widths = [ '__% CI', '__%', '__%']
colors = ['#fee08b','#fc8d59','#d53e4f']

for alpha, color, width in zip(alphas, colors, widths):
    # Grab confidence interval
    conf_ints = pollution_model.conf_int(alpha)
    
    # Pass current interval color and legend label to plot
    plt.hlines(y = conf_ints.index, xmin = conf_ints[0], xmax = conf_ints[1],
               colors = ____, ____ = width, linewidth = 10) 

# Draw point estimates
plt.plot(pollution_model.params, pollution_model.params.index, 'wo', label = 'Point Estimate')

plt.legend()
plt.show() 
编辑并运行代码