通常说误差项遵循标准的高斯分布。如果您假设这是真的,那么您的平方误差遵循卡方分布:
在概率论和统计学中,自由度为 k 的卡方分布(也称为卡方或 χ2 分布)是 k 个独立标准正态随机变量的平方和的分布。
根据您的(均方)误差,在此处查看有关如何实施准置信度指标的一些想法。它假设误差遵循卡方分布,然后使用归一化 RMSE 为给定的置信水平定义一组置信边界, α, 如下:
⎡⎣⎢nχ21−α2,n−−−−−−√RMSE,nχ2α2,n−−−−−√RMSE⎤⎦⎥
有关所涉及的步骤,请参阅链接。这是从该帖子中获取的编码模拟,并添加了一些注释(需要 python 3):
from scipy import stats
import numpy as np
s = 3 # a constant to scale the random distribution
n = 4 # number of samples/states per prediction
alpha = 0.05 # confidence interval
# distribution with confidence intervals ɑ = 0.05
c1, c2 = stats.chi2.ppf([alpha/2, 1-alpha/2], n)
# we will take this many samples (this pre-allocates the y-vector)
y = np.zeros(50000)
# Loop over each sample and record the result mean sample
# This would be your prediction vector - here it is random noise
for i in range(len(y)):
y[i] = np.sqrt(np.mean((np.random.randn(n)*s)**2))
# Use the chi-squared distributed confidence intervals to see when predictions fall
# finds percentage of samples that are inside the confidence interval
conf = mean((sqrt(n/c2)*y < s) & (sqrt(n/c1)*y > s))
print("1-alpha={:2f}".format(conf))
这是CrossValidated 上的另一个答案,它提供了该地区的更多信息。
此外,如果您假设您的预测位于高斯分布内,您可以使用预测的方差作为置信度(欢迎使用贝叶斯学习!)。
有一些软件包可以帮助您做到这一点,例如BayesOptimization。该网页上有很多示例。从本质上讲,您将能够做出预测并自动获得可靠的置信度估计......以及一些很酷的图来显示您的模型在哪里非常确定,在哪里不是:
