Skip to main content

samesame

Python Downloads Static Badge UAI 2022 Ruff

Did the target shift? Did it get worse?

Feature-level monitoring can produce alerts that are difficult to interpret, and labels may arrive too late to support early action. samesame compares one interpretable score per observation — predicted risk, prediction error, confidence, or outlier score — between source (the reference) and target (the current deployment). A model score reduces each observation to one interpretable score so each row has one number to monitor.

It separates two questions:

  • Any shift? Use ss.test_shift to ask whether the score distribution changed between source and target. This is a two-sided AUC test.
  • Harmful shift? Use ss.test_harmful_shift(..., worse="higher"|"lower") to ask whether the target moved in a specified harmful direction. This is a one-sided test based on the weighted AUC.

Quick example

import numpy as np
import samesame as ss

rng = np.random.default_rng(12345)
source_scores = rng.normal(loc=0.0, scale=1.0, size=600)
target_scores = rng.normal(loc=0.6, scale=1.0, size=600)

shift = ss.test_shift(source=source_scores, target=target_scores, rng=rng)
harm = ss.test_harmful_shift(
    source=source_scores,
    target=target_scores,
    worse="higher",  # larger = more harm (e.g., risk)
    rng=rng,
)

print(f"Shift statistic: {shift.statistic:.3f}, p-value: {shift.pvalue:.4f}")
print(f"Harm  statistic: {harm.statistic:.3f}, p-value: {harm.pvalue:.4f}")

Interpret p-values alongside the statistic and score distributions: a small p-value is evidence against label exchangeability — not business impact, causality, or the probability the null is true. Evidence of a shift is not evidence of harm.

Toy scores vs. real scores: The example uses synthetic normal scores for brevity. For real features, build the score with a domain classifier and generate it out of sample - using cross_val_predict, oob_decision_function_, or held-out data - to avoid in-sample bias. See Get started.

Workflow

  1. Build one score per observation, generating it out of sample if it comes from a fitted model.
  2. Test for any shift with ss.test_shift.
  3. Test for harmful shift with ss.test_harmful_shift(..., worse=...).
  4. If poor feature overlap is a real concern, use ss.domain_weights to reweight the comparison — weighting changes the population the comparison describes and is not a default correction.

Explore the documentation:

Read the full documentation.

Installation

python -m pip install samesame

Requires Python 3.12+, numpy, scipy, and scikit-learn.

For supported use cases and limitations, see the full documentation.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

samesame-0.4.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

samesame-0.4.1-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file samesame-0.4.1.tar.gz.

File metadata

  • Download URL: samesame-0.4.1.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for samesame-0.4.1.tar.gz
Algorithm Hash digest
SHA256 b7efd00e1fd780e5f62351ccb47da5697918632ebbe94aa3a383d3a95c67fa8b
MD5 ba107e0a13eb99cc1a46ab06f1697ad8
BLAKE2b-256 6cf7d6232a2f89985b640e5cb1db6a0cef925ba2170d4a2ba6b4489b304d9465

See more details on using hashes here.

File details

Details for the file samesame-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: samesame-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for samesame-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd3fa4eb0804e3723833cd79e2202376957fbd047af066d0d4106eead9493766
MD5 49f89dac544dad7ea3ae066d74de0915
BLAKE2b-256 f3718be4c5a356dd4e3c0177f79e4058ad3e4c3f36992fab4aa379549890c630

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.2

2 files

This release

0.4.1 This release

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

1 file

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page