gpt4 book ai didi

r - 后验概率的校准

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:23:14 28 4
gpt4 key购买 nike

目前我从事概率校准工作。我使用称为 rescaling algorithm 的校准方法 - 来源 http://lem.cnrs.fr/Portals/2/actus/DP_201106.pdf (第 7 页)。

我写的算法是:

rescaling_fun = function(x, y, z) {

P_korg = z # yhat_test_prob$BAD

P_k_C1 = sum(as.numeric(y) - 1)/length(y) # testset$BAD
P_kt_C1 = sum(as.numeric(x) - 1)/length(x) # trainset$BAD
P_k_C0 = sum(abs(as.numeric(y) - 2))/length(y)
P_kt_C0 = sum(abs(as.numeric(x) - 2))/length(x)

P_new <- ((P_k_C1/P_kt_C1) * P_korg)/((P_k_C0/P_k_C0) * (1 - P_korg) + (P_k_C0/P_k_C1) * (P_korg))

return(P_new)
}

输入值是:

1. x - train_set$BAD (actuals of `train set`)
2. y - test_set$BAD (actuals of `test set`)
3. z - yhat_test_prob$BAD (prediction on `test set`)

问题 - 结果值不在 01 范围内。你能帮忙解决这个问题吗?

最佳答案

您获取概率的公式 (P_k_C1 ...) 需要修改。例如,根据论文,y 是一个二进制变量 (0, 1),公式为 sum(y - 1)/length(y) 这最有可能是负数 - 它转换y 值为 -1 或 0,然后将它们相加。我认为它应该是 (sum(y)-1)/length(y)。下面是一个例子。

set.seed(1237)
y <- sample(0:1, 10, replace = T)
y
[1] 0 1 0 0 0 1 1 0 1 1
# it must be negative as it is sum(y - 1) - y is 0 or 1
sum(as.numeric(y) - 1)/length(y)
[1] -0.5
# modification
(sum(as.numeric(y)) - 1)/length(y)
[1] 0.4

关于r - 后验概率的校准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29948919/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com