The interview problem

Practice prompt

Two embedding datasets have similar average coordinates. Explain how a kernel two-sample test can detect other distribution differences and when its result is uninformative.

Original practice, not a reported company interview. All scenarios and worked numbers are illustrative. Interview date: not applicable. Sources retrieved September 30, 2026.

1. Scope and assumptions

Assume independent samples within and between groups for the basic test. The kernel and tuning procedure are fixed without optimizing on the same test labels unless calibration accounts for that selection.

2. Worked approach

MMD compares mean feature embeddings induced by a kernel. The squared empirical biased form averages within-X and within-Y kernel values including diagonals, then subtracts twice the average cross-group value. A suitable characteristic kernel can distinguish more than raw means; a linear kernel only measures mean differences.

Calibrate a test using valid permutations under exchangeability, or a justified analytic approximation. Store the kernel bandwidth, preprocessing and sampling unit. A significant difference identifies a distributional discrepancy, not automatically a decline in model quality or its cause.

3. Calculate the example

For X={−1,1} and Y={−2,2}, both raw means are zero, so linear-kernel MMD² is zero. Choose k(x,y)=x²y², a valid feature-product kernel for feature x². Mean features are 1 and 4, yielding biased empirical MMD²=(1−4)²=9. This kernel distinguishes these samples but is not characteristic: distributions sharing the same second moment can still be indistinguishable to it.

4. Failure cases and trade-offs

Tiny bandwidth can make almost all cross-sample similarities zero and reduce useful power. Repeated records violate naive independent permutations. Testing thousands of feature groups creates a multiple-testing problem. A large sample can detect a practically irrelevant difference.

Full pairwise kernels cost quadratic memory/work unless streamed or approximated. Random features and subsampling reduce cost at changed statistical power. Domain metrics may be more interpretable when the discrepancy of interest is already known.

5. Validate the result

Test identical distributions, mean shifts and equal-mean variance shifts. Verify the statistic by explicit kernel sums on small examples. Report effect size, calibration procedure and downstream quality measurements separately.

6. Interview follow-ups and self-review

Why can an unbiased finite-sample MMD² estimate be negative? What would a non-characteristic kernel miss?

Reward kernel-dependent distinguishability, correct example, valid test calibration and practical-significance limits.

Sources and related practice

Technical reference: jmlr.org — Primary kernel two-sample test paper; custom polynomial-feature example is original.

Exact publication/update date not established in this review. Retrieved September 30, 2026. This reference supports the named technical concept; the proposed workflow and examples are original, not a documented vendor implementation or interview report.

Continue with Model drift and production monitoring; Compare distributions with optimal transport.

Continue your preparation

Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.