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 focuses monitoring on a meaningful score per observation - such as predicted risk, prediction error, confidence, or an outlier score - and compares it between source (the reference) and target (the current deployment).

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: evidence of a shift is not evidence of harm, and statistical significance is not business impact.

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 source and target have poor overlap, use ss.domain_weights to reweight the comparison.

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.0.tar.gz (16.7 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.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: samesame-0.4.0.tar.gz
  • Upload date:
  • Size: 16.7 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.0.tar.gz
Algorithm Hash digest
SHA256 612d678e5ba3c71bbf12bcbf1eae8cad7f290b04d0a4c2376c4336f2a5834085
MD5 7435e8b7414366970ca26bc0a79c65cd
BLAKE2b-256 c5579bfce4c7700b2f91a391e9cdb911f13eadf3f91be41fbbfe7ccf6b5f20bf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: samesame-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 19.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76b80680a6e963816050537b795644dcd92d18afa56fc77abbbd6da4c22f016b
MD5 af1cd8d1058f97b9771d38bef0b1b86d
BLAKE2b-256 e0d027d76234028fd3991a1cf87cfe42590e5da7bf08b0265aed3bb10cf80c5e

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.2

2 files

0.4.1

2 files

This release

0.4.0 This release

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