A model counterfactual is an edited input that changes a prediction; a useful operational explanation must also respect immutability, feasible transitions and action authority.
Feasible counterfactual explanations for model decisions
Define the decision boundary
A pump is routed for manual inspection when its predicted follow-up risk exceeds a fixed threshold. A counterfactual search asks which allowed input changes cross that model threshold. It explains the model’s local behavior under edited inputs. It does not predict what will happen if a technician performs an action, unless that action’s causal effect was separately established.
Lock immutable and nonactionable fields
Equipment family, depot history and past failure count cannot be edited as suggested repairs. A physically mutable reading may still not be under the technician’s control. Define an allowlist of approved actions, ranges, direction constraints and dependencies from engineering policy before searching. Causal estimands are needed for claims about actual outcomes.
Keep changes coherent
Lowering a synthetic temperature while leaving a dependent alarm state unchanged may produce an impossible record. Either update linked features through a validated system model or reject the proposed edit. The code considers only an approved inspection interval and reports an edited score; it makes no claim about true failure prevention. Support checks apply here too.
Rank proposals by real cost
The numerically smallest edit may require a costly shutdown, while a slightly larger edit may be safe and routine. Score candidates by feasibility, time, parts, authority and uncertainty. Offer an abstention if no approved action crosses the model boundary. Do not fabricate recourse just because the interface expects one.
Test explanations across slices
Measure the fraction of decisions with a feasible explanation, the size and cost of edits, and whether proposals remain valid after model retraining. Inspect rare equipment and small depots, where the model may be poorly supported. Stability review records that drift.
Implementation
inspection_case = {"asset": "pump-47", "temperature": 64, "pressure": 27,
"equipment_family": "centrifugal"}
approved_temperature_settings = (64, 62, 60, 58)
decision_threshold = 0.52
def risk_score(case):
return min(1.0, max(0.0, 0.013 * case["temperature"]
+ 0.004 * case["pressure"] - 0.38))
def feasible_model_edit(case, settings, threshold):
for setting in settings:
if setting > case["temperature"] or setting < 58:
continue
candidate = {**case, "temperature": setting}
if risk_score(candidate) < threshold:
return candidate
return None
proposal = feasible_model_edit(inspection_case, approved_temperature_settings, decision_threshold)
assert risk_score(inspection_case) > decision_threshold
assert proposal is not None and proposal["temperature"] == 60
assert proposal["equipment_family"] == inspection_case["equipment_family"]Performance and operating cost
Checking A approved edits costs O(A times model inference) time and O(1) candidate storage as written. Search over many coupled fields can grow combinatorially, so constraints and candidate pruning matter. A feasible model edit is still a diagnostic artifact; verifying real-world action effects requires engineering or causal evidence.
Common Mistakes
- Do not present an edited model input as a guaranteed intervention outcome.
- Do not change immutable history or dependent fields inconsistently.
- Do not force an explanation when no approved edit exists.
