Skip to main content

Write a simple check that compares a reference window and a current window of one numeric feature and flags drift. For example, if the reference has mean 100 and standard deviation 10, and 400 current rows have mean 102, the shift is 4 standard errors and should be flagged.

Coding rounds · Intermediate 3

Short answer

Compare the two windows with a z-score for the mean, (cur_mean - ref_mean) / (ref_std / sqrt(n_cur)), and flag it beyond about 3. To catch a change in shape, bin both windows on the reference quantiles and compute the population stability index. Both are O(n); PSI above about 0.2 is a common alarm level.

Deeper answer

Clarify first: how large each window is and how often the check runs. The reference is usually the training data or a stable recent period, and the current window is the last day or week.

The mean check is z = (cur.mean() - ref.mean()) / (ref.std() / np.sqrt(len(cur))), flagged when the absolute value is above about 3. It misses a change in spread or shape. The population stability index catches those: take bin edges from the reference with np.quantile(ref, np.linspace(0, 1, 11)), open the first and last edge to minus and plus infinity so no value is dropped, compute the share of each window in each bin, and sum (a - e) * np.log(a / e) over the bins, with e the reference share and a the current share. Floor each share at a small number so an empty bin does not give a log of zero.

Test that two samples from the same distribution do not alarm, and that a shifted sample does. Interviewers watch for tiny windows, and for treating feature drift as proof that accuracy fell.

What a strong answer covers

Answer it out loud in the mock interview about 3 min

Follow-ups to expect

Common mistakes

Learn it

Monitoring and drift

Practice Coding rounds questions

More on this topic

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.