Implement Bootstrap and Jackknife Estimates on a DataFrame
Company: Pinterest
Role: Data Scientist
Category: Statistics & Math
Difficulty: medium
Interview Round: Onsite
You receive a pandas DataFrame and a statistic-producing function. Implement bootstrap and jackknife procedures to estimate uncertainty for that statistic, then explain when the two methods can be misleading.
### Constraints & Assumptions
- Each row is an independent sampling unit unless you explicitly choose a grouped resampling unit.
- The statistic function accepts a DataFrame and returns one numeric value.
- Your implementation should be reproducible under a supplied random seed.
- You may use percentile bootstrap intervals; explain limitations rather than claiming they are universally optimal.
### Clarifying Questions to Ask
- What statistic is being estimated, and is it smooth or sensitive to extremes?
- Are rows independent, or are observations clustered by user, region, or time?
- How many resamples are required, and which confidence level should be returned?
- Can the statistic fail or become undefined on some resamples?
### What a Strong Answer Covers
- Bootstrap sampling with replacement at the correct observational unit and deterministic random-state handling.
- A distribution of bootstrap estimates, standard error, and clearly labeled percentile interval.
- Leave-one-out jackknife estimates, their mean, and the standard jackknife variance formula.
- Correct handling of grouping, missing values, unstable statistics, and computational cost.
- Discussion of bias, skewness, nonsmooth statistics, small samples, dependence, and more suitable variants when needed.
### Follow-up Questions
1. How would you bootstrap a user-level metric when each user has many rows?
2. Why can a naive row bootstrap fail for time-series data?
3. What is the difference between the bootstrap sample size and the number of bootstrap replications?
4. When would you prefer a block bootstrap or stratified bootstrap?
Quick Answer: Implement bootstrap and jackknife uncertainty estimates for a statistic computed from a pandas DataFrame. Learn correct positional resampling, confidence intervals, leave-one-out variance, grouped sampling, reproducibility, and failure modes for dependent or nonsmooth data.