samesame
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_shiftto 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
- Build one score per observation, generating it out of sample if it comes from a fitted model.
- Test for any shift with
ss.test_shift. - Test for harmful shift with
ss.test_harmful_shift(..., worse=...). - If poor feature overlap is a real concern, use
ss.domain_weightsto reweight the comparison — weighting changes the population the comparison describes and is not a default correction.
Explore the documentation:
- Get started - learn the workflow and run both tests in five minutes.
- Monitor a credit model - work through risk, confidence, and error monitoring with HELOC data.
- Weight for common support - learn when and how to reweight comparisons.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7efd00e1fd780e5f62351ccb47da5697918632ebbe94aa3a383d3a95c67fa8b
|
|
| MD5 |
ba107e0a13eb99cc1a46ab06f1697ad8
|
|
| BLAKE2b-256 |
6cf7d6232a2f89985b640e5cb1db6a0cef925ba2170d4a2ba6b4489b304d9465
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd3fa4eb0804e3723833cd79e2202376957fbd047af066d0d4106eead9493766
|
|
| MD5 |
49f89dac544dad7ea3ae066d74de0915
|
|
| BLAKE2b-256 |
f3718be4c5a356dd4e3c0177f79e4058ad3e4c3f36992fab4aa379549890c630
|