Assemble a predictive dataset
Use tabular data that reflects the decision context and encode constraints (immutable features, allowed ranges) before training.
Generate counterfactual explanations. Assess feasibility and stability.
Counterfactual explanations describe minimal input changes that would flip a model prediction. Implementing them requires a predictive model, a method to search or optimise for alternative inputs, and evaluation of plausibility, stability and actionability.
Learning concept · Not a validated service
Counterfactual explanations describe minimal input changes that would flip a model prediction. Implementing them requires a predictive model, a method to search or optimise for alternative inputs, and evaluation of plausibility, stability and actionability.
A proposed application: provide human-readable “what-if” suggestions for model decisions, for example showing applicants which few features to change to alter a risk classification; any deployment should keep a human reviewer in the loop and not be used for automated high-stakes decisions.
Use tabular data that reflects the decision context and encode constraints (immutable features, allowed ranges) before training.
Fit and validate a classifier that the counterfactual method will probe; ensure calibration and reasonable test performance.
Add a search or optimisation method (e.g. DiCE, gradient-based or integer programmes) that finds plausible minimal changes to inputs.
Measure stability, proximity, sparsity and feasibility, and perform spot checks with domain experts for actionability.
The supplied starter generates a synthetic binary classification dataset, trains a RandomForestClassifier, computes permutation feature importances on the test set, and prints the model score and top features. It does not compute or demonstrate any counterfactual explanations.
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42, stratify=y)
model = RandomForestClassifier(n_estimators=250, random_state=42)
model.fit(X_train, y_train)
importance = permutation_importance(model, X_test, y_test, n_repeats=10, random_state=42)
report = pd.DataFrame({"feature": columns, "importance": importance.importances_mean})The starter trains a classifier on synthetic data and reports permutation importance but does not implement any counterfactual-generation algorithm (no DiCE, optimisation, or nearest-counterfactual search), nor does it show example counterfactual inputs or evaluate explanation metrics.
Proposed extension: replace synthetic data with a real tabular decision dataset, add a counterfactual generator (e.g. DiCE or a constrained optimiser), and produce a reviewable panel that shows candidate counterfactuals with feasibility checks.
This is a potential application pathway, not a delivered product. The supplied starter does not implement this service or validate it with real users.
Networkers Home runs this topic inside its AI Engineer Course, with placement support and hands-on labs.