Skip to content
svgrules-scatter

Association rules

Which item combinations co-occur often and reliably, beyond chance?

Demo data · seed 20261101 · 90 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read x as how common the rule is and y as how often it holds.
  2. Read colour as lift: how much more often than chance.
  3. Prefer rules that are high on all three.
  1. Callout 1: High confidence, but rare.
  2. Callout 2: Common but less reliable.
  3. Callout 3: Colour scale: lift.

Watch out

  • Confidence can be high only because the consequent is common: use lift. Many rules means some look strong by chance.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the host's cs-ml evaluation or the Python/R engine); the chart computes nothing statistical.
  • Support = share of transactions containing all items; confidence = P(consequent | antecedent); lift = confidence ÷ P(consequent) (> 1 means the items co-occur more than by chance).
  • High confidence with lift near 1 only reflects a popular consequent.
# Association rules — Codesplash Chart Lab (recipe "rules-scatter")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("rules-scatter-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
SUP = "support"
CONF = "confidence"
LIFT = "lift"
LAB = "rule"
d = df.dropna(subset=[SUP, CONF, LIFT])
cmap = LinearSegmentedColormap.from_list("seq", [SEQ[0], SEQ[-1]])
fig, ax = plt.subplots(figsize=(8, 5))
sc = ax.scatter(d[SUP], d[CONF], c=d[LIFT], cmap=cmap, s=30, edgecolors=GREY, linewidths=0.4)
for _, row in d.nlargest(5, LIFT).iterrows():  # the highest-lift rules
    ax.annotate(str(row[LAB]), (row[SUP], row[CONF]), xytext=(4, 4), textcoords="offset points", fontsize=7)
fig.colorbar(sc, ax=ax, label=LIFT)
ax.set_xlabel(SUP)
ax.set_ylabel(CONF)
plt.show()

Needs pandas, numpy, matplotlib · reads rules-scatter-demo.csv · app theme from the optional codesplash helper