Counterfactual Proximity is a metric that quantifies the distance between the original input instance and the generated counterfactual, typically measured using L1 (Manhattan) or L2 (Euclidean) norms. It operationalizes the principle of minimal change, ensuring that the explanation is as close to the factual instance as possible while still crossing the decision boundary.
Glossary
Counterfactual Proximity

What is Counterfactual Proximity?
A metric quantifying the distance between an original input instance and its generated counterfactual to enforce minimal, interpretable change.
Minimizing proximity is a core objective in algorithmic recourse because closer counterfactuals are generally more interpretable and require less user effort. However, optimizing solely for proximity can produce unrealistic or non-actionable instances; therefore, it is often balanced with plausibility constraints and sparsity to ensure the generated explanation lies within the data manifold.
Key Properties of Counterfactual Proximity
The fundamental properties that define how 'close' a counterfactual is to the original instance, balancing minimal change against real-world plausibility.
L1 (Manhattan) Distance
Measures proximity as the sum of absolute differences across all features. This metric naturally promotes sparsity because deviations are penalized linearly, encouraging solutions where most features remain unchanged and only a few are altered.
- Formula: Σ |x_i - x'_i|
- Key Benefit: Generates highly interpretable, sparse counterfactuals.
- Use Case: Ideal for tabular data where changing a small number of categorical or binary features is preferred.
L2 (Euclidean) Distance
Calculates proximity as the straight-line distance between the original and counterfactual points in feature space. It penalizes large deviations more heavily due to squaring, distributing changes across many features in small increments.
- Formula: √(Σ (x_i - x'_i)²)
- Key Benefit: Finds the geometrically closest point across the decision boundary.
- Trade-off: Often results in dense changes to many features, which can reduce actionability for a human end-user.
Mahalanobis Distance
A proximity metric that accounts for the data distribution by incorporating the inverse covariance matrix. It scales distances based on feature variance and correlation, ensuring the counterfactual lies within high-density regions.
- Plausibility: Prevents generating unrealistic outliers that technically cross the boundary but are not representative of real data.
- Mechanism: A deviation along a high-variance feature is penalized less than the same deviation along a low-variance feature.
Weighted Proximity
Applies a custom weight vector to the distance calculation, reflecting the relative cost of changing each feature. This directly encodes domain knowledge about actionability.
- Immutable Features: Assigned infinite weight to prevent any change.
- Actionable Features: Lower weights for easily modifiable attributes like 'savings amount' vs. high weights for 'years of education'.
- Implementation: Often combined with L1 or L2 norms as a weighted sum: Σ w_i * |x_i - x'_i|.
Sparsity as a Proximity Proxy
While not a distance metric itself, the L0 norm (counting the number of changed features) is a critical property of proximity. A counterfactual is considered more interpretable if it alters only a handful of features.
- Human Constraint: Users can only process a limited number of recommended changes.
- Optimization: Direct L0 minimization is NP-hard, so L1 regularization is used as a convex relaxation to induce sparsity.
Proximity vs. Plausibility Trade-off
The closest counterfactual in raw Euclidean space is often an adversarial example—a point outside the training data manifold. Effective proximity must be balanced with a plausibility constraint.
- Density Estimation: Penalizes points in low-density regions.
- Autoencoder Reconstruction Error: Measures how well a counterfactual can be reconstructed by a model trained only on real data.
- Result: A slightly more distant but realistic recommendation is always preferred over a nonsensical, proximal one.
Frequently Asked Questions
Explore the core concepts behind counterfactual proximity, the metric that quantifies the minimal change required to alter a model's prediction, ensuring explanations are both actionable and realistic.
Counterfactual proximity is a metric that quantifies the distance between an original input instance and its generated counterfactual, enforcing the principle of minimal change. Formally, it is defined as the result of a distance function—typically an L1 (Manhattan) or L2 (Euclidean) norm—applied to the difference vector between the factual input x and the counterfactual x'. The objective is to minimize d(x, x') subject to the constraint that the model's prediction f(x') equals the desired target outcome. A lower proximity score indicates a more interpretable and less costly explanation, as it requires fewer alterations to the original feature vector. This metric is foundational to generating sparse counterfactuals, where the L1 norm is often preferred because it promotes solutions where only a few feature coordinates change, making the explanation easier for a human operator to understand and act upon.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Explore the core concepts that define and constrain the distance between an original instance and its counterfactual, ensuring minimal, realistic, and actionable explanations.
Mahalanobis Distance
A distance metric that accounts for feature correlations and variances in the training data distribution. Unlike Euclidean (L2) distance, it measures distance in terms of standard deviations from the mean, ensuring the counterfactual lies within high-density regions. This prevents generating unrealistic instances that are technically close in raw feature space but are statistical outliers, directly enforcing plausibility.
Sparse Counterfactual
A counterfactual instance that alters the prediction by changing only a small number of features. Sparsity is often enforced by adding an L1 regularization term (Lasso) to the objective function during generation. This is critical for human interpretability, as a user can only process a limited number of changes. The trade-off between proximity and sparsity is a central optimization challenge in counterfactual generation.
Plausible Counterfactual
A counterfactual instance that lies within the high-density region of the training data distribution. Proximity alone is insufficient; a counterfactual can be close to the query point but still be an adversarial artifact that would never occur in reality. Plausibility metrics often use the log-likelihood of the counterfactual under the data distribution or the distance to the k-nearest neighbors in the training set.
Growing Spheres Algorithm
A model-agnostic counterfactual generation algorithm that searches for the closest counterfactual by expanding a hypersphere around the query instance. It samples points on the surface of an expanding sphere until a point is found that crosses the decision boundary. This method directly optimizes for proximity without requiring gradient access, making it applicable to any black-box classifier.
Feasibility Constraint
A hard rule encoded into a counterfactual generation algorithm that prevents the modification of immutable features or enforces causal monotonicity. For example, a constraint might prevent decreasing a user's age or increasing their education level without also increasing their years of experience. These constraints define the boundary of the action set and ensure the generated counterfactual represents a realistic path to recourse.
Counterfactual Validity
A binary evaluation metric that verifies whether a generated counterfactual instance successfully flips the model's prediction to the target outcome. It is the most fundamental requirement: if validity is 0, the counterfactual is useless. However, optimizing solely for validity often produces distant or unrealistic instances, necessitating a multi-objective optimization that balances validity with proximity, sparsity, and plausibility.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us