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

63. 使用 Welch's t-test 统计量比较两次 eval 运行结果

MediumProbability and statistics

两个 prompt 版本在 eval 中的得分不同。Welch's t-test 用于在不假设方差相等的情况下,判断这种差距是否大于噪声。

为两个各至少包含 2 个值的 1D 样本编写 welch_t(a, b)。使用 ddof=1 的样本方差。返回 (t, df),其中 t = (mean_a - mean_b) / sqrt(va / na + vb / nb),df 是 Welch-Satterthwaite 自由度:(va/na + vb/nb)^2 / ((va/na)^2 / (na - 1) + (vb/nb)^2 / (nb - 1))。

函数def welch_t(a, b)

示例 1

输入: a = [1, 2, 3], b = [4, 5, 6]

输出: t = -3.674 and df = 4

示例 2

输入: a = [0.8, 0.82, 0.79, 0.85, 0.81], b = [0.74, 0.9, 0.7]

输出: (0.54872, 2.114331)

约束条件

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

Both the t statistic and the degrees of freedom are built from the same two pieces: each sample's variance divided by its size.

提示 2

Compute the sample variance with ddof=1 for each array, divide by its length to get s_a and s_b, use them for t, then plug the same values into the Welch-Satterthwaite formula.

提示 3

With sa = a.var(ddof=1) / len(a), the df is (sa + sb) ** 2 / (sa ** 2 / (na - 1) + sb ** 2 / (nb - 1)). Return both as plain Python floats.

理解思路

两个 prompt 版本得到了不同的平均 eval 分数。这种差距是真实的还是仅仅是噪声?Welch's t 统计量通过将均值之差除以其标准误差来计算,并且不假设两个样本具有相等的方差。随后,自由度公式会告诉你应该与哪个 t 分布进行比较。

Worked example

a = [2, 4, 6], b = [1, 1, 1, 4]. Mean a = 4, sample variance (n - 1 divisor) = 8 / 2 = 4. Mean b = 1.75, variance = 6.75 / 3 = 2.25. va / na = 1.3333 and vb / nb = 0.5625, sum 1.8958. t = (4 - 1.75) / sqrt(1.8958) = 2.25 / 1.3769 = 1.634. df = 1.8958^2 / (1.3333^2 / 2 + 0.5625^2 / 3) = 3.594 / 0.9944 = 3.61.

t = (mean_a - mean_b) / sqrt(va / na + vb / nb) with ddof = 1 variances; df = (va / na + vb / nb)^2 / ((va / na)^2 / (na - 1) + (vb / nb)^2 / (nb - 1)). 使用 ddof = 0 会缩小方差并放大 t 值。常用于比较 A/B eval 运行结果和 prompt 变体。
主题
Probability and statistics
相似题目
  • 使用双比例 z 检验判断新 prompt 是否真的转化率更高Medium
  • 使用 Beta prior 更新你对模型通过率的认知Medium
  • 为评估分数计算 bootstrap 置信区间Medium
  • 使用平均并列排名计算 Spearman 秩相关系数Medium
所有 Probability and statistics 道题目
反馈
63 / 903
Python 3solution.pyPython 空闲
1
2
3
4
5
6
import numpy as np
​
def welch_t(a, b):
# your code here
pass
​

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

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