Correlated features and counterfactual limits
Quick answer
Correlated features can make explanations unstable or misleading. A counterfactual explanation identifies a changed input that changes a model prediction, subject to constraints; it is not proof that changing reality will cause that outcome. Static examples tested locally with Python 3.13.5, scikit-learn 1.8.0 SciPy 1.17.0 and NumPy 2.3.5 where imported. ByteMind package execution is unverified.
Find a constrained model counterfactual
start=1; b=1; target=7valid=[a for a in range(5) if 2*a+b>=target]print(min(valid,key=lambda a:(abs(a-start),a)))print(any(2*a+b>=target for a in range(3)))Observed local output:
3FalseThe model target is reachable only if the actuator can reach 3 or higher.
How it works
If x1≈x2, a model may distribute coefficients across both or choose one depending on regularization, noise and seed. Similar predictive accuracy can coexist with different attribution ranks. Compare coefficients in common units, repeat fitting on development resamples, and report rank or sign stability. Group importance can expose shared reliance; conditional resampling attempts to preserve relationships but depends on a valid conditional model. A counterfactual search minimizes a distance or cost d(x,x') subject to f(x') meeting a target and x' being feasible. In a synthetic machine-temperature example, setpoint may be adjustable but the machine identifier is not; sensor readings constrained by physics must not be changed independently. Explicitly document mutable coordinates, bounds, joint constraints, search space, tie policy and whether a solution exists. A nearest grid candidate is not necessarily a globally minimal continuous solution. Verify the proposed model output, not merely a surrogate score. Do not turn model explanations into personal decisions.
Show coefficient instability under nearly duplicate columns
import numpy as npfrom sklearn.linear_model import LinearRegressionx=np.arange(6,dtype=float); z=np.array([1,-1,1,-1,1,-1],dtype=float); X=np.column_stack([x,x+.001*z])a=LinearRegression().fit(X,x+.01*z); b=LinearRegression().fit(X,x-.01*z)print(np.round(a.coef_,2).tolist(),np.round(b.coef_,2).tolist())print(bool(np.max(np.abs(a.predict(X)-b.predict(X)))<.03))Observed local output:
[-9.0, 10.0] [11.0, -10.0]TrueA small target perturbation changes coefficient signs while predictions remain close on these rows.
Common mistakes
Do not propose changing immutable or downstream measurement fields as actionable interventions. Do not equate prediction flip with causal outcome, or promise minimality outside the searched grid. Do not hide sensitivity across seeds or correlated inputs.
Practice and next steps
For a toy equipment score f(a,b)=2a+b, start at [1,1], change only a within integers 0..4 and seek score at least 7. Check the nearest candidate and discuss feasibility if the allowed maximum were 2. Complete the knowledge check and staged exercise. Next: Neural networks and backpropagation.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Correlated features and counterfactual limits — knowledge check
Apply correlated features and counterfactual limits to new scenarios.
Why can coefficients vary strongly for correlated inputs?
Which variable should a counterfactual freeze?
No feasible candidate meets the target. Return?
Does a model prediction flip guarantee an outcome flip?
What should a stability report compare?