BLOGLLM Logo
Go Pro
Guest
Not signed in
All BlogsCoursesPracticeInterview prepSeriesTagsBookmarksPricing
Log in
All BlogsCoursesPracticeTagsBookmarksPricing
My PrepProblemsStudy PlansResearch PapersRoadmapInterviewContestsLeaderboardGames
Articles
Practice / Probability and statistics11 of 24 in topic

62. Put a bootstrap confidence interval on an evaluation score

MediumProbability and statistics
Asked atMicrosoft

An agent that passes 62 percent of 50 test tasks might really be a 50 percent agent or a 75 percent agent. A bootstrap interval shows that uncertainty without any distribution assumptions.

Write bootstrap_ci(x, n_boot=1000, alpha=0.05, seed=0) for a 1D array x of length n. Follow these steps exactly so results are reproducible:
1. rng = np.random.default_rng(seed).
2. idx = rng.integers(0, n, size=(n_boot, n)), sampling with replacement.
3. means = mean of x[idx] along axis 1.
4. Return (lo, hi) as a tuple of floats: np.percentile(means, 100 * alpha / 2) and np.percentile(means, 100 * (1 - alpha / 2)), default linear interpolation.

Inputs can be Python lists or NumPy arrays, so convert them with np.asarray first.

Functiondef bootstrap_ci(x, n_boot=1000, alpha=0.05, seed=0)

Example 1

for x of all 1s every resample has mean 1, so the result is (1.0, 1.0).

Example 2

Input: x = np.ones(10)

Output: (1.0, 1.0)

Example 3

Input: x = [0.0, 0.0, 0.0, 10.0], n_boot = 200, seed = 1

Output: (0.0, 7.5)

Constraints

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

Resample the data with replacement many times, record each resample's mean, and read the interval off the spread of those means.

Hint 2

Make rng = np.random.default_rng(seed), draw an index matrix of shape (n_boot, n) with rng.integers, take x[idx].mean(axis=1), then use np.percentile for the two tails.

Hint 3

rng.integers excludes the upper bound, so call it as rng.integers(0, n, size=(n_boot, n)); the percentiles are 100 * alpha / 2 and 100 * (1 - alpha / 2), returned as floats.

Understand the idea

The bootstrap estimates how uncertain a statistic is by resampling your own data. Draw n values with replacement many times, compute the mean of each resample, and read off percentiles of those means as a confidence interval. No normal-distribution assumption is needed. Like re-running a small survey many times by reshuffling the answers you already have.

Worked example

x = [0, 1]. A resample of size 2 can be [0, 0], [0, 1], [1, 0] or [1, 1], with means 0, 0.5, 0.5, 1. So about a quarter of bootstrap means are 0, half are 0.5 and a quarter are 1, and a 95% interval comes out near (0, 1), wide because two points tell you little. For all-ones data every mean is 1, giving (1.0, 1.0). Note rng.integers(0, n) excludes n, so it covers every index; using n - 1 would never pick the last element.

idx = rng.integers(0, n, (n_boot, n)); means = x[idx].mean(1); lo, hi = percentiles at 100 alpha / 2 and 100 (1 - alpha / 2)

Agent eval reports use bootstrap intervals.

Topics
Probability and statistics
Companies1
  • Microsoft a candidate reported this question Microsoft Machine Learning Engineer Interview Questions | Screna AI

From public interview reports and guides. Not affiliated with or endorsed by these companies.

Similar questions
  • Decide if a new prompt really converts better with a two-proportion z-testMedium
  • Update your belief about a model's pass rate with a Beta priorMedium
  • Compare two eval runs with Welch's t-test statisticMedium
  • Compute Spearman rank correlation with averaged tie ranksMedium
All Probability and statistics problems
Report
62 / 903
Python 3solution.pyPython idle
1
2
3
4
5
6
import numpy as np
​
def bootstrap_ci(x, n_boot=1000, alpha=0.05, seed=0):
# your code here
pass
​

Run checks these cases in your browser, no sign-in needed. Submit checks all 4 tests.

Ctrl/Cmd + Enter to run
© BlogLLM, Bengaluru, IndiaAboutTermsPrivacyRefundsDMCAContactRSS