BLOGLLM Logo
Go Pro
Guest
Not signed in
所有博客课程练习面试准备系列标签书签价格
Log in
All BlogsCoursesPracticeTagsBookmarksPricing
My PrepProblemsStudy PlansResearch PapersRoadmapInterviewContestsLeaderboard游戏
Articles
练习 / Probability and statistics10 of 24 in topic

61. 使用 Beta prior 更新你对模型通过率的认知

MediumProbability and statistics

你在任务上运行一个 agent,它通过了一些任务。仅凭 10 次运行,9 次通过并不意味着 90% 的通过率。Beta(a, b) prior 加上通过/失败的计数,会得到 Beta(a + passes, b + fails) 后验分布。

编写 beta_update(a, b, results),其中 results 是一个包含 1 (pass) 和 0 (fail) 的列表。返回后验分布的 (post_a, post_b, mean, var),对于 Beta(a, b):
mean = a / (a + b)
var = a b / ((a + b) ** 2 (a + b + 1))

函数def beta_update(a, b, results)

示例 1

输入: a = 1, b = 1, results = [1] * 9 + [0]

输出: (10.0, 2.0, 0.833333, 0.010684)

示例 2

输入: a = 20, b = 20, results = [1, 1, 1]

输出: (23.0, 20.0, 0.534884, 0.005654)

示例 3

输入: a = 2, b = 3, results = []

输出: (2.0, 3.0, 0.4, 0.04)

约束条件

  • Python 3 standard library. Code runs in your browser.
  • Your code must pass all 3 tests to be accepted.
提示 1

The Beta prior is conjugate to pass/fail data, so updating it just means adding counts to a and b.

提示 2

Count passes as sum(results) and fails as len(results) minus that, add them to a and b, then use the mean and variance formulas on the new values.

提示 3

Plug the posterior values, not the prior ones, into var = A*B / ((A+B)**2 * (A+B+1)), and return all four numbers as floats.

常见错误
  • 后验均值会将小样本向 prior 方向收缩;错误的实现版本会直接报告原始通过率。
理解思路

Beta(a, b) 分布描述了你对未知成功率的认知。你可以将 a 理解为在看到任何数据之前观察到的虚拟通过次数,将 b 理解为虚拟失败次数。每一次真实的通过都会让 a 加 1,每一次失败会让 b 加 1,因此更新过程本质上就是计数。这可以防止小样本结果显得过于极端,就像不会因为一家新餐厅只有两条好评就完全相信它的满分一样。

Worked example

prior 为 Beta(1, 1),结果为 9 次通过和 1 次失败。后验分布为 Beta(10, 2)。Mean = 10 / 12 = 0.833,而不是 0.9。Variance = (10 x 2) / (12^2 x 13) = 20 / 1872 = 0.0107。

使用后验值计算 post_a = a + passes, post_b = b + fails; mean = a / (a + b); var = a b / ((a + b)^2 (a + b + 1))。在评估集较小时,团队使用这种方法来报告 agent 或模型通过率,并体现诚实的置信度(uncertainty)。
主题
Probability and statistics
相似题目
  • 使用双比例 z 检验判断新 prompt 是否真的转化率更高Medium
  • 为评估分数计算 bootstrap 置信区间Medium
  • 使用 Welch's t-test 统计量比较两次 eval 运行结果Medium
  • 使用平均并列排名计算 Spearman 秩相关系数Medium
所有 Probability and statistics 道题目
反馈
61 / 903
Python 3solution.pyPython 空闲
1
2
3
4
def beta_update(a, b, results):
# your code here
pass
​

Run 会在浏览器中检查这些用例,无需登录。 Submit 会检查所有 3 个测试。

Ctrl/按 + 回车 运行
© BlogLLM, Bengaluru, India关于条款隐私退款DMCA联系我们RSS