The interview problem
A teammate proposes replacing correlation-based feature selection with mutual information. Explain what this fixes and what it cannot fix. Work through an XOR target, a nonlinear dependence with zero correlation, and a unique-record-ID feature. Design a validation pipeline that avoids selecting features merely because of sampling noise or leakage.
Original ML fundamentals practice, not a reported company interview. Examples and calculations are illustrative. Primary reference retrieved September 27, 2026; publication date not stated; interview date not applicable.
Quick answer
Mutual information measures how much observing one variable reduces uncertainty about another. It can detect dependence that correlation misses, but it does not establish causation. Specify the log base, estimator and evaluation split before comparing feature scores.
1. Define the distribution and units
For finite discrete variables X and Y, define I(X;Y)=Σx,y p(x,y) log[p(x,y)/(p(x)p(y))]. Terms with zero joint probability contribute zero. Every positive joint cell has positive marginals, so its denominator is positive. Natural logarithms give nats; base-two logarithms give bits. Divide nats by log(2) to convert to bits.
This is KL divergence between the joint distribution and the product of its marginals. It is symmetric, nonnegative, and zero exactly when the variables are independent. Unlike Pearson correlation, it does not only measure linear association. For discrete variables, I(X;Y)=H(Y)−H(Y|X), and it is bounded above by the smaller marginal entropy.
Exactly summing the plug-in formula also gives a nonnegative result, apart from numerical rounding. Other estimation procedures can produce negative estimates through estimation error; that does not make true MI negative.
These are population statements. A number computed from a finite table is the mutual information of that empirical distribution, not proof of the population value. The variables, population, observation time and sampling mechanism must be specified before interpreting a score.
2. Compute the XOR counterexample
Let A and B be independent fair bits, and let Y=A XOR B. The four equally likely rows (A,B,Y) are (0,0,0), (0,1,1), (1,0,1) and (1,1,0). Y is also a fair bit, so H(Y)=1 bit.
For A and Y, each of the four joint combinations has probability 1/4 and each marginal value has probability 1/2. Every ratio in the MI sum is (1/4)/(1/2 × 1/2)=1. Thus I(A;Y)=0. The same calculation gives I(B;Y)=0. Neither feature alone helps predict the target.
Now treat the pair Z=(A,B) as a single four-valued variable. Each occupied (Z,Y) cell has joint probability 1/4, while p(Z)p(Y)=1/8. The ratio is 2, so I(Z;Y)=4 × (1/4) × log2(2)=1 bit. Knowing both features determines the target completely.
Conditional MI averages the MI of the conditional distributions over the conditioning variable. Conditioning on B also makes A informative: I(A;Y|B)=1 bit. The chain rule gives I((A,B);Y)=I(B;Y)+I(A;Y|B)=0+1. Conditional MI can therefore exceed the corresponding marginal MI. A univariate MI filter that drops both zero-score features destroys all predictive information in this example.
The remedy is not to blindly enumerate every feature combination. Retain plausible interacting variables, compare interaction-capable models, and evaluate selection as part of the complete learning procedure. Exhaustive interaction search has computational costs and increases opportunities to overfit.
3. Show dependence that correlation misses
Take X uniformly distributed over −1, 0 and 1, and set Y=X². E[X]=0, E[Y]=2/3, and E[XY]=E[X³]=0. Both variances are positive, so Pearson correlation is zero. Yet Y is completely determined by X.
Since H(Y|X)=0, I(X;Y)=H(Y)=−(1/3)log2(1/3)−(2/3)log2(2/3)=0.918296 bits, or 0.636514 nats. This example shows an actual advantage over correlation. It does not imply that a linear predictive model can exploit the dependence without a suitable transformation such as X².
MI is unchanged by bijective relabeling of discrete categories. It does not use an arbitrary numeric ordering of category IDs. In contrast, correlation of numerical encodings can change when categories are reassigned different numbers. Measurement semantics still matter: an ID can be a valid category mathematically and a useless feature operationally.
4. Build and inspect the empirical table
For N observations, count each joint cell nxy and its row and column totals nx and ny. The plug-in estimator is Σoccupied cells (nxy/N) log[N nxy/(nx ny)]. Count tables can be sparse; there is no need to materialize every possible category pair. Verify that totals agree and decide explicitly how missing observations enter the population.
The official scikit-learn mutual_info_score function computes this discrete contingency-table quantity and returns nats. Its clustering-label interface does not make it a continuous-density estimator. Passing distinct floating-point measurements as category labels changes the statistical problem.
A contingency table with counts [[40,10],[10,40]] has uniform marginals. In bits its MI is 0.8 log2(1.6)+0.2 log2(0.4)=0.278072. The negative contribution from the off-diagonal cells is legitimate; only the total must be nonnegative. Clamping individual contributions produces the wrong answer.
Zero observed counts are not evidence of impossible population events. Smoothing the table can stabilize some calculations, but changes the estimated distribution. State the smoothing rule, choose it without peeking at the final test set, and report sensitivity rather than hiding the choice.
5. Diagnose the unique-ID trap
Suppose 100 rows have distinct IDs and a balanced binary target. In the empirical distribution, each ID occurs with exactly one label. Therefore Ĥ(Y|ID)=0 and Î(ID;Y)=Ĥ(Y)=1 bit, even if IDs were generated independently of labels and new IDs reveal nothing about future targets.
This is a concrete finite-sample overfitting failure. Under population independence, the true MI is zero, but a nonnegative plug-in estimate can be positive merely because the observed table is sparse. Do not assume a universal bias correction works for every cardinality, dependence structure and estimator.
Permuting the balanced labels across these unique IDs still gives one label per ID and the same one-bit score. A correctly constructed permutation comparison would show that the observed score is not exceptional relative to this null. Simply seeing a large raw score would miss that conclusion.
A held-out set does not automatically repair this if you recompute a fresh empirical ID-versus-label MI table on that set: IDs are again unique, so the same artifact recurs. Instead fit the predictive procedure on training data and measure its predictions for genuinely unseen IDs under an explicit unknown-category policy. This distinction separates distribution estimation from out-of-sample prediction.
6. Design the selection and validation pipeline
define target and prediction-time feature availability
↓
split by time, entity or independent unit
↓
fit discretization / estimator and selection on training folds
↓
compare main effects and plausible interactions
↓
fit predictor and evaluate untouched validation folds
↓
freeze procedure, then evaluate final test dataKeep preprocessing and feature selection inside each training fold. Selecting features on all labels before cross-validation leaks validation information. If trying many estimators, bin counts, interactions or subsets, the selection process itself needs validation; the best of many noisy scores is optimistic.
For a permutation null, preserve the exchangeability assumptions of the study. Independent-row shuffling can be inappropriate for repeated customers, time series or clustered samples. Choose a justified block or group scheme where possible; otherwise do not attach a nominal significance interpretation to an invalid randomization.
Report sample size, category counts, occupancy, estimator settings and uncertainty. Compare against an appropriate null and a useful predictive baseline. Bootstrap intervals do not automatically remove estimator bias, and resampling individual rows from a dependent dataset can understate uncertainty.
Feature availability is a separate requirement. A post-outcome status can have perfect MI with the label while being unavailable at prediction time. Audit source timestamps and actual ingestion availability. Even a reproducible predictive association can disappear under a change in population or data collection.
7. Separate continuous estimation from discrete counting
For continuous variables, MI is defined through the joint distribution relative to the product distribution; when densities exist it can be written as an integral of a log density ratio. Differential entropies are not interchangeable with discrete entropies. A deterministic relation between non-atomic continuous variables can give infinite MI rather than a convenient finite score.
Binning a continuous variable computes information about its discretized representation. Coarser bins can erase relevant structure; increasingly fine bins can create a sparse-table artifact like the unique-ID example. Fit bin boundaries on training data and examine stability. A continuous estimator has its own smoothness, neighborhood and dimensionality assumptions; its numerical output is not automatically comparable to a differently configured estimator.
At the population level, a deterministic transformation cannot increase information about Y beyond the original X. This data-processing property concerns the true distributions. Two finite-sample estimates can appear to violate it because of different estimation errors, so it is a diagnostic rather than a license to treat estimated numbers as exact identities.
8. Explain what the score cannot decide
Mutual information measures association, not causal effect, usefulness under a particular loss, or feature acquisition cost. A shared cause can make X and Y dependent without an intervention on X changing Y. A feature with higher MI need not give the best practical result under a restricted model class, skewed costs or production constraints.
Redundancy and synergy both matter. Two copies of a useful feature can each score highly while adding no incremental information. XOR has the opposite structure: individually useless features become perfectly informative together. Conditional MI can help describe these relationships, but estimating high-dimensional conditional distributions is harder and requires more evidence.
Follow-ups: Why does zero correlation not imply independence? Why does zero population MI imply independence? How does the XOR answer change when one input is biased? Why does held-out table recomputation fail for unique IDs? Can MI be negative? What changes when logarithm base changes? Why can conditioning increase MI?
9. Self-review rubric
- Define the variables, population, joint distribution and log units.
- Compute both marginal and joint-feature MI for XOR.
- Give a zero-correlation example with positive dependence.
- Distinguish population MI, empirical table MI and predictive validation.
- Explain the unique-ID artifact and its permutation behavior.
- Keep selection and preprocessing within training folds.
- Handle discrete versus continuous estimation explicitly.
- Avoid causal claims and account for redundant or interacting features.
A shared cause can explain all the information
Let Z be a fair binary variable, and let X = Z and Y = Z. The only observed pairs are (0,0) and (1,1), each with probability 1/2. Knowing X determines Y, so I(X;Y) = 1 bit. Once Z is known, neither X nor Y has residual uncertainty: I(X;Y | Z) = 0.
This toy distribution illustrates why a strong feature score does not show that changing X will change Y. Both could encode the same upstream condition. In real data, decide what Z means before conditioning: controlling for a mediator can remove part of a causal effect, and conditioning on a collider can introduce dependence. Conditional mutual information is a statistical quantity, not an automatic causal adjustment rule.
Interview check: explain why zero correlation, zero mutual information and zero conditional mutual information answer different questions. Estimate any data-dependent preprocessing inside the training split, and measure held-out predictive value separately.
Sources and related practice
scikit-learn: mutual_info_score, publication date not stated; retrieved September 27, 2026. Primary reference for the discrete contingency-table formula, symmetry, category relabeling and nats. Examples, derivations and the validation design here are original worked practice.
Continue with KL divergence direction and selection bias.
Continue your preparation
Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.