Have a go at it. The editor and the docs panel are open, and your code is saved as you type. Running it needs a free account — you’ll come back to exactly what you wrote.
Standard Error and a Confidence Interval
The standard error is the standard deviation of the estimate, not of the data:
It answers a different question. The sample standard deviation s says how spread out your observations are. The standard error says how much your mean would move if you collected a fresh sample. Those are not the same number and confusing them is the most common statistics error in ML writeups.
Note the n: to halve your uncertainty you need four times the data. This is why a model evaluated on 100 test examples has a genuinely wobbly accuracy, and why a 0.3% improvement on such a test set is noise.
An approximate 95% interval is the estimate plus or minus about two standard errors:
x = [2, 4, 6, 8] mean = 5.0 s (ddof=1) = 2.582 SE = 2.582/2 = 1.291 95% CI = 5.0 +/- 1.96*1.291 = [2.470, 7.530]
Your task:
Implement mean_confidence_interval(x, z) returning [low, high] — a two-element list.
Use the unbiased sample standard deviation (ddof=1).
Example Tests
Four evenly spaced points, at roughly 95% confidence
Input: {"x":[2,4,6,8],"z":1.96}
Expected: [2.46965,7.53035]
A sample with no spread gives an interval of zero width
Input: {"x":[3,3,3],"z":1.96}
Expected: [3,3]
A wider multiplier gives a wider interval around the same mean
Input: {"x":[1,2,3,4,5],"z":2.58}
Expected: [1.17566,4.82434]
import numpy as np
def mean_confidence_interval(x, z):
"""
A z-based confidence interval for the sample mean.
Args:
x: array of observations, shape (n,)
z: multiplier, e.g. 1.96 for roughly 95%
Returns:
list of two floats: [lower bound, upper bound]
"""
# YOUR CODE HERE
pass