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 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_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: 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
- 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 source and target have poor overlap, use
ss.domain_weightsto reweight the comparison.
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.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
612d678e5ba3c71bbf12bcbf1eae8cad7f290b04d0a4c2376c4336f2a5834085
|
|
| MD5 |
7435e8b7414366970ca26bc0a79c65cd
|
|
| BLAKE2b-256 |
c5579bfce4c7700b2f91a391e9cdb911f13eadf3f91be41fbbfe7ccf6b5f20bf
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76b80680a6e963816050537b795644dcd92d18afa56fc77abbbd6da4c22f016b
|
|
| MD5 |
af1cd8d1058f97b9771d38bef0b1b86d
|
|
| BLAKE2b-256 |
e0d027d76234028fd3991a1cf87cfe42590e5da7bf08b0265aed3bb10cf80c5e
|