What-If Tool

Also known as: WIT

On this page 7

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.

WorkspaceWhat it showsTypical question
Datapoint editorEach example with editable feature valuesWhat if this applicant earned more
Performance and fairnessConfusion matrices, ROC curves, thresholds by sliceIs error rate equal across groups
FeaturesDistribution statistics for every featureIs a feature skewed or missing
Facets Dive viewScatter and binning of all examples by any fieldWhere do misclassified examples cluster
Main workspaces of the What-If Tool

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.

TechniqueMechanismInsight providedCaveat
Manual editChange feature values and re-run inferenceLocal sensitivity of one predictionEdits may create unrealistic inputs
Nearest counterfactualSearch for closest example with another labelContrastive explanation from real dataLimited to examples in the dataset
Partial dependenceSweep one feature, hold others fixedShape of feature effectMisleading with correlated features
Model comparisonRun two models on the same dataWhere models disagreeNeeds a shared input format
Exploration techniques available in the tool

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.

StrategyConstraint appliedTrade-off
Custom thresholdThresholds chosen manuallyFull control, no guarantee
Single thresholdOne threshold for all groupsSimple, may produce unequal error rates
Demographic parityEqual share of positive predictions per groupCan lower accuracy for some groups
Equal opportunityEqual true positive rate per groupFalse positive rates may differ
Equal accuracyEqual accuracy per groupError types may still differ
Group thresholdsCost-optimal threshold per groupExplicit differential treatment
Threshold strategies offered for binary classification

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.

ApproachOutputScopeBest audience
What-If ToolInteractive views and counterfactualsLocal and slice-levelAnalysts, product and policy teams
SHAP and KernelSHAPAdditive attribution per featureLocal, aggregated to globalData scientists
LIMELocal surrogate weightsLocalData scientists
AnchorsIf-then rules with precisionLocalDomain experts
Learning Interpretability ToolViews for text and multimodal modelsLocal and slice-levelNLP practitioners
Positioning against neighboring interpretability approaches

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.