You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FAQ] Homework 3 (2026) Q3: Why do mutual_info_classif scores differ from mutual_info_score, or change on every run? #468
Homework 3 (2026), Q3: I computed mutual information with sklearn.feature_selection.mutual_info_classif instead of mutual_info_score. My scores are different, they change with random_state, and sometimes lead_source and employment_status tie at 0.03. Which function should I use?
Answer
Use sklearn.metrics.mutual_info_score, as in the module 3 lesson. It computes the exact MI between two discrete variables from their contingency table, so the result is deterministic:
mutual_info_classif is a different tool, designed for feature selection. There are two common traps on this dataset:
1. Label-encoded categories are treated as continuous. With the default discrete_features='auto' and a dense X, the integer codes are treated as continuous. sklearn then uses a k-nearest-neighbours estimator that adds random noise, so the result is approximate and seed-dependent. On the training split:
call
lead_source
employment_status
mutual_info_score (exact)
0.0343
0.0190
mutual_info_classif(X, y, random_state=0)
0.0342
0.0194
mutual_info_classif(X, y, random_state=1)
0.0178
0.0056
mutual_info_classif(X, y, random_state=42)
0.0319
0.0300 ← both round to 0.03
Passing discrete_features=True makes it exact and identical to mutual_info_score:
2. One-hot columns split a feature's information. If you run MI on pd.get_dummies or DictVectorizer output, every category becomes its own binary column. The top column is then employment_status=employed (0.016), ahead of any single lead_source column (0.014 at most), which points you to the wrong answer. Q3 asks about the variables, so compute MI on the original categorical columns.
Also note: mutual_info_score returns nats (natural log), not bits, so values are small. The argument order doesn't matter, because MI is symmetric. Use the training set only.
Activity
github-actions commentedon Oct 19, 2026
✅ FAQ NEW proposal created in PR #469
Please review and approve the changes.