Quick Overview

This question evaluates a data scientist's competence in statistical inference using bootstrap resampling, proficiency with numerical computing for large sample operations, and attention to performance optimization.

Calculate 95% Bootstrap Confidence Interval for Order Values

Company: Pinterest

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

##### Scenario An e-commerce firm wants a 95% confidence interval for the average order value but only has a single historical sample of order amounts. ##### Question Given an array of past order values, write efficient Python code to return the 95% bootstrap confidence interval using 10,000 resamples. Explain your approach and any performance optimizations. ##### Hints Use vectorized resampling (np.random.choice) and percentile bounds; avoid Python loops.

Quick Answer: This question evaluates a data scientist's competence in statistical inference using bootstrap resampling, proficiency with numerical computing for large sample operations, and attention to performance optimization.

Given a non-empty list of historical order values (floats), compute a two-sided 95% bootstrap confidence interval for the mean using exactly 10,000 resamples with replacement. Use NumPy's Generator-based RNG for reproducibility: numpy.random.default_rng(seed).choice. Return the 2.5th and 97.5th percentile bounds of the bootstrap sample means as a list [low, high], rounded to 6 decimal places. If the list has one unique value, the interval is that value for both bounds.

Constraints

  • 1 <= len(order_values) <= 5000
  • Order values are finite floats (can be zero or positive)
  • Use exactly B = 10,000 bootstrap resamples with replacement
  • RNG must be numpy.random.default_rng(seed) for determinism
  • Percentile bounds are [2.5, 97.5]
  • Return a list of two floats rounded to 6 decimals

Hints

  1. Use numpy.random.default_rng(seed).choice to generate resamples in a vectorized way.
  2. Compute means along axis=1 and then np.percentile at [2.5, 97.5].
  3. To limit memory, generate resamples in batches (e.g., 1000 at a time) while keeping vectorization within each batch.

Loading coding console...