Skip to content

Visualising predictions

Open In Colab

Splink contains a variety of tools to help you visualise your predictions.

The idea is that, by developing an understanding of how your model works, you can gain confidence that the predictions it makes are sensible, or alternatively find examples of where your model isn't working, which may help you improve the model specification and fix these problems.

# Rerun our predictions to we're ready to view the charts
from splink import Linker, DuckDBAPI, splink_datasets


db_api = DuckDBAPI()
df = splink_datasets.fake_1000
df_sdf = db_api.register(df)
df_sdf.as_duckdbpyrelation().limit(5).show()
┌───────────┬────────────┬─────────┬────────────┬─────────┬─────────────────────────┬─────────┐
│ unique_id │ first_name │ surname │    dob     │  city   │          email          │ cluster │
│   int64   │  varchar   │ varchar │    date    │ varchar │         varchar         │  int64  │
├───────────┼────────────┼─────────┼────────────┼─────────┼─────────────────────────┼─────────┤
│         0 │ Robert     │ Alan    │ 1971-06-24 │ NULL    │ robert255@smith.net     │       0 │
│         1 │ Robert     │ Allen   │ 1971-05-24 │ NULL    │ roberta25@smith.net     │       0 │
│         2 │ Rob        │ Allen   │ 1971-06-24 │ London  │ roberta25@smith.net     │       0 │
│         3 │ Robert     │ Alen    │ 1971-06-24 │ Lonon   │ NULL                    │       0 │
│         4 │ Grace      │ NULL    │ 1997-04-26 │ Hull    │ grace.kelly52@jones.com │       1 │
└───────────┴────────────┴─────────┴────────────┴─────────┴─────────────────────────┴─────────┘
import urllib.request
from pathlib import Path


def get_settings_text() -> str:
    # assumes cwd is repo root
    local_path = Path.cwd() / "docs" / "demos" / "demo_settings" / "saved_model_from_demo.json"

    if local_path.exists():
        return local_path.read_text()

    # fallback location for settings - the file as it is on master, for e.g. colab use
    # TODO: update ref
    url = "https://raw.githubusercontent.com/moj-analytical-services/splink/master/docs/demos/demo_settings/saved_model_from_demo.json"
    with urllib.request.urlopen(url) as u:
        return u.read().decode()
import json

settings = json.loads(get_settings_text())


linker = Linker(df_sdf, settings)
df_predictions = linker.inference.predict(threshold_match_probability=0.2)
Blocking time: 0.01 seconds


Predict time (post-blocking): 0.05 seconds

Waterfall chart

The waterfall chart provides a means of visualising individual predictions to understand how Splink computed the final matchweight for a particular pairwise record comparison.

To plot a waterfall chart, the user chooses one or more records from the results of linker.inference.predict(), and provides these records to the linker.visualisations.waterfall_chart() function.

For an introduction to waterfall charts and how to interpret them, please see this video.

records_to_view = df_predictions.as_record_list(limit=5)
linker.visualisations.waterfall_chart(records_to_view, filter_nulls=False)

Comparison viewer dashboard

The comparison viewer dashboard takes this one step further by producing an interactive dashboard that contains example predictions from across the spectrum of match scores.

An in-depth video describing how to interpret the dashboard can be found here.

linker.visualisations.comparison_viewer_dashboard(df_predictions, "scv.html", overwrite=True)

# You can view the scv.html file in your browser, or inline in a notbook as follows
from IPython.display import IFrame

IFrame(src="./scv.html", width="100%", height=1200)

Cluster studio dashboard

Cluster studio is an interactive dashboards that visualises the results of clustering your predictions.

It provides examples of clusters of different sizes. The shape and size of clusters can be indicative of problems with record linkage, so it provides a tool to help you find potential false positive and negative links.

df_clusters = linker.clustering.cluster_pairwise_predictions_at_threshold(
    df_predictions, threshold_match_probability=0.5
)

linker.visualisations.cluster_studio_dashboard(
    df_predictions,
    df_clusters,
    "cluster_studio.html",
    sampling_method="by_cluster_size",
    overwrite=True,
)

# You can view the scv.html file in your browser, or inline in a notbook as follows
from IPython.display import IFrame

IFrame(src="./cluster_studio.html", width="100%", height=1000)
Completed iteration 1, num edges remaining to process: 360


Completed iteration 2, num edges remaining to process: 4


Completed iteration 3, num edges remaining to process: 0

Further Reading

For more on the visualisation tools in Splink, please refer to the Visualisation API documentation.

📊 For more on the charts used in this tutorial, please refer to the Charts Gallery.

Next steps

Now we have visualised the results of a model, we can move on to some more formal Quality Assurance procedures using labelled data.