简体   繁体   English

围绕预测线 plot 绘制置信区间

[英]Plotting confidence interval around predicted line plot

I am trying to plot confidence intervals around a line plot, similar to this: https://scikit-learn.org/0.17/_images/plot_gp_regression_001.png我正在尝试围绕一条线 plot 的 plot 置信区间,类似于此: https://scikit-plot-learn.org/0.17/0_images1.png_gression_gre

I am fitting a gaussian process and when predicting values, for each, it returns a mean and a std (standard deviation).我正在拟合一个高斯过程,并且在预测每个值时,它返回一个平均值和一个标准差(标准差)。 Using this, I should be able to able to plot different ranges of the confidence interval.使用这个,我应该能够 plot 不同范围的置信区间。 For my case, I am trying to have ranges for 10%, 20%, ... 90%.就我而言,我试图将范围设置为 10%、20%、... 90%。

Currently I am doing something like this目前我正在做这样的事情

y_pred, std = reg.predict(x, return_std=True)

std_z = 1.96 # from z-table for 95%
confidence_interval = std * std_z

plt.plot(x, y_pred)    
plt.fill_between(x, y_pred - confidence_interval, y_pred + confidence_interval)

That works.这样可行。 According to the z-table (http://www.z-table.com/uploads/2/1/7/9/21795380/8573955.png?759 ), you can see that the z value is 1.96 for 95%.根据 z-table (http://www.z-table.com/uploads/2/1/7/9/21795380/8573955.png?759 ),可以看到 z 值为 1.96 表示 95% . However, take for example 25% and 75%.但是,以 25% 和 75% 为例。 The z values for those would be - and + 0.67 respective, which would just overlap in the confidence interval when plotting.这些 z 值将分别为 - 和 + 0.67,在绘图时它们只会在置信区间内重叠。 This seems intuitively incorrect to me.这在我看来直觉上是不正确的。 I would expect expect shrinking bands for lower confidence ranges and expanding ones for increasing, right?我预计较低的置信度范围会缩小,而增加的置信度范围会扩大,对吗?

Any help would be appreciated.任何帮助,将不胜感激。

Wrong.错误的。 The percentages associated with confidence intervals (95%, 75%, 25% in your examples) are coverage probabilities.与置信区间相关的百分比(在您的示例中为 95%、75%、25%)是覆盖概率。 They're the chance that the true value of quantity you're estimating (the predicted value in this case) lies within the CI.. Given that the CI's you're talking about are central confidence intervals (that is, they are centred on the predicted value) it stands to reason that for a higher confidence, you need a wider interval.它们是您估计的数量的真实值(在这种情况下为预测值)位于 CI 内的机会。鉴于您正在谈论的 CI 是中心置信区间(也就是说,它们以预测值)按理说,要获得更高的置信度,您需要更宽的区间。 This is exactly what you are seeing.这正是您所看到的。 If a narrower confidence interval had a higher coverage probabiulity than a wider one, then that would imply that there was a region that somehow had a negative coverage probability associated with it.如果更窄的置信区间比更宽的置信区间具有更高的覆盖概率,那么这意味着存在一个区域以某种方式具有与其相关的负覆盖概率。 Probabilities can't be negative, so that's impossible.概率不能为负,所以这是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM