Knowledge / Artificial Intelligence and Data Science / Feature selection and model interpretability

Feature selection and model interpretability

Artificial Intelligence and Data Science (B.E./B.Tech) · Machine learning · free study notes for exams, placements and interviews

In short

Feature selection is the task of choosing a small, useful subset of input variables from a larger set, and model interpretability is the task of explaining what a trained model has learned and why it made a particular prediction. Both attack the same practical problem: a model with 500 noisy inputs is slower, overfits more, costs more to serve and cannot be defended to a regulator or a business user. University syllabi examine filter/wrapper/embedded methods, the information-theoretic measures behind them, regularisation-based selection and the modern explanation tools (SHAP, LIME, PDP, permutation importance); GATE DA asks numerical questions on mutual information, chi-square and information gain. In Indian industry this is everyday work in credit scoring and fraud at HDFC, ICICI, Bajaj Finserv, Paytm and Razorpay, where RBI expects lenders to explain adverse decisions, and in healthcare and insurance analytics; interviewers almost always ask "which features mattered and how do you know?"

Explained

Why select features at all

Filter methods (model-independent, run before training)

Wrapper methods (use the model's own score)

Embedded methods (selection happens during training)

Interpretability: concepts and intrinsic models

Post-hoc explanation techniques

Indian practice, regulation and fairness

Key points

Formulas and examples

Pearson correlation: r = Σ(xᵢ−x̄)(yᵢ−ȳ) / √[Σ(xᵢ−x̄)² · Σ(yᵢ−ȳ)²]; dimensionless, −1 ≤ r ≤ 1
Entropy: H(Y) = −Σ p(y) log₂ p(y) — bits. Conditional entropy H(Y|X) = Σ p(x) H(Y|X=x)
Information gain / mutual information: I(X;Y) = H(Y) − H(Y|X) = H(X) + H(Y) − H(X,Y) — bits, ≥ 0
Symmetric uncertainty: SU = 2 I(X;Y) / [H(X) + H(Y)] — normalised to 0-1
Chi-square: χ² = Σ (Oᵢⱼ − Eᵢⱼ)²/Eᵢⱼ, with Eᵢⱼ = (row total × column total)/N; df = (r−1)(c−1)
ANOVA F = [Σ nⱼ(x̄ⱼ − x̄)²/(k−1)] / [Σ Σ (xᵢⱼ − x̄ⱼ)²/(N−k)]; k groups, N observations
VIF for feature j: VIF_j = 1/(1 − R²_j), R²_j from regressing xⱼ on all other features
Lasso: minimise ‖y − Xβ‖² + λ Σ|βⱼ| · Ridge: minimise ‖y − Xβ‖² + λ Σβⱼ² · Elastic Net: + λ[αΣ|βⱼ| + (1−α)Σβⱼ²]
mRMR score of feature f: I(f;Y) − (1/|S|) Σ_{s∈S} I(f;s), S = already selected set
Permutation importance: PIⱼ = M(model, D) − (1/K) Σₖ M(model, D with column j shuffled); M = metric (AUC, accuracy, R²)
Shapley value: φⱼ = Σ_{S ⊆ F\{j}} [|S|!(|F|−|S|−1)!/|F|!] · [v(S ∪ {j}) − v(S)]; additivity: f(x) = φ₀ + Σⱼ φⱼ
PDP: PD(x_S) = (1/n) Σᵢ f(x_S, x_C⁽ⁱ⁾) — average prediction sweeping feature(s) S over the observed others

Example 1 - Information gain of a feature (loan default). 200 applicants, 80 default (Y=1), 120 repay. Feature "salaried/self-employed": salaried 120 applicants with 30 defaults; self-employed 80 applicants with 50 defaults.

Example 2 - Chi-square filter on the same table.

DefaultRepayTotal
Salaried3090120
Self-employed503080
Total80120200

Example 3 - VIF and redundancy. Regressing monthly_income on annual_income, EMI and age gives R² = 0.96; regressing age on the rest gives R² = 0.21.

Example 4 - Permutation importance with AUC. Baseline validation AUC = 0.842. Shuffling each column (mean of 5 repeats):

Feature shuffledAUC afterPI = 0.842 − AUC
credit_bureau_score0.7630.079
debt_to_income0.8110.031
enquiries_6m0.8260.016
account_vintage0.8390.003
pin_code_hash0.844−0.002

Example 5 - SHAP additivity for one applicant. Model outputs log-odds. Base value φ₀ = −1.20. Contributions: bureau_score +0.85, DTI −0.55, enquiries_6m −0.30, vintage +0.10.

from sklearn.feature_selection import SelectKBest, mutual_info_classif, RFECV
from sklearn.linear_model import LogisticRegression, LassoCV
from sklearn.pipeline import Pipeline
from sklearn.inspection import permutation_importance, PartialDependenceDisplay
from sklearn.model_selection import cross_val_score, StratifiedKFold

# filter + model as ONE pipeline so selection stays inside each CV fold
pipe = Pipeline([("sel", SelectKBest(mutual_info_classif, k=15)),
                 ("clf", LogisticRegression(max_iter=1000))])
print(cross_val_score(pipe, X, y, cv=StratifiedKFold(5), scoring="roc_auc").mean())

# embedded: L1 logistic -> non-zero coefficients are the selected features
l1 = LogisticRegression(penalty="l1", solver="liblinear", C=0.1).fit(Xs, y)
kept = X.columns[(l1.coef_[0] != 0)]

# wrapper: RFE with CV-chosen subset size
rfe = RFECV(LogisticRegression(max_iter=1000), step=1, cv=5, scoring="roc_auc").fit(Xs, y)

# post-hoc: permutation importance on the VALIDATION set, then SHAP
r = permutation_importance(model, X_val, y_val, n_repeats=10, scoring="roc_auc")
# import shap; shap.TreeExplainer(model).shap_values(X_val)
FamilyCostUses model?Handles interactionsTypical tools
FilterLowNoNochi², ANOVA F, mutual information, VIF, mRMR
WrapperHighYes (repeatedly)Yesforward/backward, RFE, RFECV, GA
EmbeddedMediumYes (once)PartlyLasso, Elastic Net, tree gain, Boruta
Explanation toolScopeModel-agnosticMain weakness
Coefficients / odds ratiosGlobalNoLinear models only, unstable under collinearity
Tree pathLocalNoOnly for single shallow trees
MDI (Gini) importanceGlobalNoTrain-set bias, cardinality bias
Permutation importanceGlobalYesCorrelated features share credit
PDP / ICE / ALEGlobalYesPDP misleads under correlation
LIMELocalYesUnstable, sampling-dependent
SHAPLocal + globalYesCostly except TreeSHAP; assumes feature independence in some variants
CounterfactualLocalYesMay suggest unachievable changes

Where it is used

Interview questions

Common mistakes

Related topics

Dimensionality reduction and PCA · Overfitting, bias-variance and regularisation · Decision trees and random forests · Ensemble methods and gradient boosting · Model evaluation metrics · Machine learning workflow

Open in the Knowledge reader →Find jobs →