Skip to main content

Statistical tests for model monitoring, data validation, and drift detection.

Project description

samesame

Development Status Python Downloads Static Badge UAI 2022 uv Ruff

Same, same but different ...

samesame helps you compare a source sample with a target sample.

It answers two practical questions:

  • Did anything change? Use test_shift(...).
  • Did things get worse? Use test_adverse_shift(...).

Use it for model monitoring, data validation, drift assessment, or any workflow where you need to compare two groups and determine whether the difference is practically important.

Who is this for?

samesame is useful whenever you need to compare a source group and a target group, for example:

  • Model monitoring — Does production data still look like training data?
  • Data validation — Does this new batch look like the data I expect?
  • Drift detection — Did something change between last month and this month?
  • Group comparison — Do two customer groups, regions, or experiments look meaningfully different?

Installation

python -m pip install samesame

Quick Start

Suppose you already have one score per row for a source sample and a target sample. Larger scores should indicate either worse outcomes or unusual ones. The score usually comes from a (pre-trained) model. For example, you might train a classifier to distinguish between the source and target data, then use the predicted probabilities as scores. Or you might use a model's confidence or prediction errors as scores. The choice of score depends on your application and what kind of shift you want to detect.

import numpy as np
from samesame import test_adverse_shift, test_shift

rng = np.random.default_rng(123_456)
source_scores = rng.normal(size=600)
target_scores = rng.normal(size=600)

shift = test_shift(source=source_scores, target=target_scores)
print(f"Did anything change?  p-value = {shift.pvalue:.4f}")

harm = test_adverse_shift(
    source=source_scores,
    target=target_scores,
    direction="higher-is-worse",
)
print(f"Did things get worse? p-value = {harm.pvalue:.4f}")

How to read this: a small p-value from test_shift(...) indicates evidence that the target sample differs from the source sample. A small p-value from test_adverse_shift(...) indicates evidence that it has also shifted in a worse direction. If the first is small and the second is large, the data changed but not in a clearly harmful way.

How it works

samesame does not compare raw tables directly. The usual workflow is:

  1. Turn each row into one score — typically from a classifier trained to distinguish the two groups.
  2. Compare those scores with test_shift(...) (did anything change?) and test_adverse_shift(...) (did it get worse?).

Both tests are permutation-based, so no distributional assumptions are required.

When you know that source and target have different feature distributions — covariate shift — you can supply per-sample importance weights to focus the test on the region where both groups overlap. See Adjust for covariate shift with importance weights.

Where to go next

Step-by-step examples are available in the documentation:

Tutorials

How-to guides

Dependencies

samesame has minimal dependencies. It is built on top of, and fully compatible with, scikit-learn and numpy.

Project details


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.3.1.tar.gz (17.9 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.3.1-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: samesame-0.3.1.tar.gz
  • Upload date:
  • Size: 17.9 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.3.1.tar.gz
Algorithm Hash digest
SHA256 8694a1432ad7925d8f1105c568d529d63c01239f717be648cc9bf930f349f10c
MD5 8306f05f4440bce38df847bf84d3e924
BLAKE2b-256 ea71a9f16c0f2d109763a3beb2e64e43521e3d56bbf2500ae9edbf5a17e5f34b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: samesame-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 22.7 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c67e89cbc64dc2d78b94fbd34912abce80b6e49c26121d65e7a7818580a0e725
MD5 d44e478dad35ff673ccb8b95f66556c4
BLAKE2b-256 03c1d0406ee2e14257ab8d51967712f6a3c128991a63f21ed9a1089c62ea0c90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page