Skip to main content

Low-level statistical tests for comparing source and target score distributions.

Project description

samesame

Development Status Python Downloads Static Badge UAI 2022 uv Ruff

Same, same but different ...

samesame compares a reference group with a new group and tells you whether the new group looks different, and whether it moved in a worse direction.

In the package, the reference group is called source and the new group is called target. That could mean training vs production data, a baseline batch vs a fresh batch, or one segment vs another.

The package is built around two practical questions:

  • Did anything change?
  • Did the change point in a worse direction?

You answer those questions with the signal that matches your use case: predicted risk, model confidence, prediction error, or a classifier score used to compare two datasets.

Start here

Quick example

import numpy as np
import samesame as ss

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

shift = ss.shift.detect_shift(source_scores, target_scores)
harm = ss.shift.detect_harm(
    source_scores,
    target_scores,
    direction="higher-is-worse",
)

print(f"Shift p-value: {shift.pvalue:.4f}")
print(f"Harm  p-value: {harm.pvalue:.4f}")

A small p-value from detect_shift(...) means the groups differ. A small p-value from detect_harm(...) means the target group also moved in the declared worse direction.

Common signals

Choose the signal that matches the decision you need to make:

  • Predicted risk when higher values already mean higher business risk.
  • Prediction error when labels are available and you want to measure accuracy directly.
  • Confidence score when you want to monitor certainty rather than business impact.
  • Domain-classifier score when your goal is to detect distribution shift between datasets.

The package does not force one interpretation on you. It gives you a small set of tests you can reuse across these settings.

Why it works well in practice

samesame is statistically grounded, but the working model is simple:

  1. Build a numeric signal for source and target.
  2. Test for any change with ss.shift.detect_shift(...).
  3. Test for directional harm with ss.shift.detect_harm(...) when direction matters.

Both tests are permutation-based, which keeps the assumptions light. When source and target differ in feature support, ss.weights.from_domain_probabilities(...) lets you focus the test on the region where the two groups are genuinely comparable.

Pick a guide

Installation

python -m pip install samesame

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.2.tar.gz (12.1 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.2-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: samesame-0.3.2.tar.gz
  • Upload date:
  • Size: 12.1 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.2.tar.gz
Algorithm Hash digest
SHA256 3e0f7973d4b63e88fb924c0562a966169cebbd64b45baac3902c5f907bc58c74
MD5 1ce4b3a704ef85685f73b6eb5fe74f6d
BLAKE2b-256 367c16275cde508eb06db6bc8f85f650e1d7b9d00369f27ce07a9a8840f25862

See more details on using hashes here.

File details

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

File metadata

  • Download URL: samesame-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 12.5 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eebc9cd82ab28a945b3f5afef855ecee89255503bb722422d4b897cb40875289
MD5 b837b7bd864ae13656ea1c8861cb4f95
BLAKE2b-256 6ac47e0774aed6f86f5e948a18e4a4acc7e0c5fa784b42fa72028c85865b1120

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