The What-If Tool (WIT) is an open-source interactive interface for probing the behavior of trained machine learning models without writing code. Released by Google’s People + AI Research (PAIR) team in 2018, it lets a user load a dataset and one or two models, then edit individual data points, find counterfactual examples, plot partial dependence and compare performance and fairness metrics across subgroups.
In Explainable AI, the What-If Tool belongs to the family of model-agnostic, example-based inspection tools. It does not compute a single attribution score like SHAP or LIME; instead, it supports hypothesis-driven exploration, asking what the model would predict if one feature changed, and which nearby example receives a different outcome.
How the What-If Tool inspects a model
The What-If Tool works by querying the model as a black box: it sends examples to a prediction function, collects scores or labels, and renders the results in a browser-based dashboard. It runs as a TensorBoard plugin, inside Jupyter and Colab notebooks, and with models served through TensorFlow Serving or a cloud prediction endpoint. In notebooks, a custom prediction function allows models from scikit-learn, XGBoost, PyTorch or any Python callable.
Because it only needs inputs and outputs, the tool is model-agnostic and requires no access to gradients or weights. The interface is organized into workspaces, summarized below.
| Workspace | What it shows | Typical question |
|---|---|---|
| Datapoint editor | Each example with editable feature values | What if this applicant earned more |
| Performance and fairness | Confusion matrices, ROC curves, thresholds by slice | Is error rate equal across groups |
| Features | Distribution statistics for every feature | Is a feature skewed or missing |
| Facets Dive view | Scatter and binning of all examples by any field | Where do misclassified examples cluster |
Counterfactuals and partial dependence in WIT
The most distinctive feature of the What-If Tool is its nearest counterfactual search. For a selected data point, it finds the most similar example in the dataset that received a different classification, measured by L1 or L2 distance over normalized features. Comparing the two examples side by side shows which feature differences plausibly drive the decision.
Partial dependence plots in WIT vary one feature across its range while holding the others fixed, for a single example or across the dataset. The single-example version is effectively an individual conditional expectation plot, and it reveals thresholds, monotonic trends or unstable regions of the decision function.
| Technique | Mechanism | Insight provided | Caveat |
|---|---|---|---|
| Manual edit | Change feature values and re-run inference | Local sensitivity of one prediction | Edits may create unrealistic inputs |
| Nearest counterfactual | Search for closest example with another label | Contrastive explanation from real data | Limited to examples in the dataset |
| Partial dependence | Sweep one feature, hold others fixed | Shape of feature effect | Misleading with correlated features |
| Model comparison | Run two models on the same data | Where models disagree | Needs a shared input format |
Fairness analysis and threshold optimization
For binary classifiers, the What-If Tool can slice the dataset by a sensitive feature and display per-group confusion matrices, false positive and false negative rates and ROC curves. It then offers threshold optimization strategies that set a classification threshold globally or per group to satisfy a chosen fairness definition, given a user-defined cost ratio between false positives and false negatives.
| Strategy | Constraint applied | Trade-off |
|---|---|---|
| Custom threshold | Thresholds chosen manually | Full control, no guarantee |
| Single threshold | One threshold for all groups | Simple, may produce unequal error rates |
| Demographic parity | Equal share of positive predictions per group | Can lower accuracy for some groups |
| Equal opportunity | Equal true positive rate per group | False positive rates may differ |
| Equal accuracy | Equal accuracy per group | Error types may still differ |
| Group thresholds | Cost-optimal threshold per group | Explicit differential treatment |
These strategies make the incompatibility of fairness definitions visible: satisfying one criterion usually violates another. The tool shows the trade-off but does not decide which definition is legally or ethically appropriate.
What-If Tool compared with other explanation methods
The What-If Tool complements rather than replaces feature attribution libraries. Its strength is interactive, visual exploration for mixed audiences, while libraries such as Captum, InterpretML or SHAP produce numerical attributions suited to pipelines and reports.
| Approach | Output | Scope | Best audience |
|---|---|---|---|
| What-If Tool | Interactive views and counterfactuals | Local and slice-level | Analysts, product and policy teams |
| SHAP and KernelSHAP | Additive attribution per feature | Local, aggregated to global | Data scientists |
| LIME | Local surrogate weights | Local | Data scientists |
| Anchors | If-then rules with precision | Local | Domain experts |
| Learning Interpretability Tool | Views for text and multimodal models | Local and slice-level | NLP practitioners |
Google later introduced the Learning Interpretability Tool (LIT) for language and multimodal models, and active WIT development has slowed. WIT remains most useful for tabular classification and regression on moderate dataset sizes.
Limitations and practical pitfalls
The tool runs inference in the browser session, so datasets of more than a few thousand rows become slow and are usually sampled. Its explanations are observational, and several pitfalls recur in practice.
- Unrealistic edits: changing one feature can create combinations that never occur in real data.
- Correlated features: partial dependence can attribute effects to the wrong variable.
- Sample bias: conclusions drawn from a small sampled slice may not generalize.
- Fairness without context: a metric gap signals a question, not a verdict, and requires domain review.
Good practice is to treat findings from the What-If Tool as hypotheses to verify with held-out data, statistical tests and complementary methods such as permutation feature importance or accumulated local effects. Teams should also record the sampled slice, the model version and the chosen threshold strategy, so that the analysis is reproducible during audits and can be repeated after retraining.
Setup also deserves attention. Input data is usually supplied as tf.Example records or Python lists, and a mismatch between the feature encoding used in training and the one passed to the tool produces silently wrong predictions. Checking a handful of known examples against production scores before exploring prevents misleading conclusions.
Explained without jargon
The What-If Tool is a control panel for asking a model questions. You pick one case, such as a loan application. Then you change one detail, like income, and see whether the answer changes.
It can also find the most similar case that got the opposite answer. Seeing the two side by side shows what tipped the decision. The tool also checks whether the model treats different groups of people equally. The key idea is learning by experiment, not by reading formulas.
A typical use case
A credit risk team at a regional bank tests a gradient-boosted model that approves small personal loans. A data scientist loads 5,000 sampled applications into the What-If Tool in a notebook, using a custom prediction function. Slicing by age group shows that applicants under 25 have a noticeably higher false negative rate than older applicants with similar repayment histories.
Using the nearest counterfactual search, the team finds that many rejected young applicants differ from approved ones mainly in length of credit history. Partial dependence plots confirm a sharp drop in score below two years of history. The team reviews the feature with compliance, adds alternative repayment signals and retrains. The outcome is a smaller error gap between age groups, documented in the model card before deployment.