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

Uploaded Python 3

File details

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

File metadata

  • Download URL: samesame-0.3.0.tar.gz
  • Upload date:
  • Size: 17.5 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.0.tar.gz
Algorithm Hash digest
SHA256 43e392afbc4f7d897b800de51da9bee78330480ada369791a6172752d146f9a9
MD5 b265da4c273fa4cb3cafaf01af371714
BLAKE2b-256 f3319a86ae84ef0d16d3c08efa540be3ad22897aafb4806dcff9d9d1df470f67

See more details on using hashes here.

File details

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

File metadata

  • Download URL: samesame-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 22.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c275cfc9245f682b9d39c0cd676b7089d3240cc90fe875ff81cc30719f36dd0
MD5 74480d327932eff643ade2dfbb50277f
BLAKE2b-256 8613639cb37eb08fc7bb4f958e73bca42bd448651dd452b44fddc0bdb28f89ac

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