samesame¶
Scores shift in production. Most shifts are harmless.
New users, devices, or conditions can change how a system behaves. That does not, by itself, mean people are worse off. Treat every alert as a failure and you chase normal variation; dismiss every alert and a real decline can go unchecked.
Use samesame to check a change against a concern you care about, or to compare a candidate model with the one in use on the same cases.
Choose the question¶
Choose a test by the decision you need to make, not just because an alert fired.
| Test | Use it to ask |
|---|---|
MannWhitneyU |
Do values in the group under review tend to rank higher or lower than values in the reference group? |
Dsos |
Did a score move toward the high end you chose as harmful? |
DeLong |
On the same cases, does the candidate rank outcomes better than the current model? |
Venkatraman |
On the same cases, do the models make different trade-offs between catching cases and false alarms? |
For more guidance on choosing, see Choose a test.
Install¶
You need Python 3.12 or a later version.
python -m pip install samesame
# or
uv add samesame
Try a first check¶
Suppose you want to check whether predicted risk tends to be higher in a new group. Here, source is the reference group and target is the group under review. Give each observation one numeric value—in this case, predicted risk. Higher means riskier. Make a holder, configure it, call it, then read pvalue. For real model scores, use predictions from cases the model did not train on. Record the seed and number of permutations if you need to repeat the run.
import numpy as np
import samesame as ss
source = np.array([0.10, 0.22, 0.28, 0.35])
target = np.array([0.30, 0.42, 0.55, 0.61])
test = ss.MannWhitneyU(source, target)
test = test.set_permutation(
seed=np.random.default_rng(12345),
n_permutations=9999,
)
shift = test()
print(shift.pvalue, shift.statistic)
Expected output: 0.056 0.94. The target scores tend to rank higher than the source scores. This is a score difference, not a result about whether outcomes got worse.
Next steps¶
| Your task | Start here |
|---|---|
| Compare two groups of items | Compare outcomes |
| Watch the scores of a model in use | Monitor model scores |
| Compare two models on shared labels | Compare models |
| Compare groups with partial overlap | Weight for common support |
Further reading¶
- Are you OK? Test for harmful (adverse) shift and In gentle praise of classifier tests — two posts by the author.
- Equivalence and Noninferiority Testing Using SAS/STAT Software — the case study behind the treatment example.
- Related R package:
dsosand its 10-minute crash course.
Why “samesame”? The name comes from the expression “same, same … but different,” used in parts of the world for things that seem alike but are not identical. Score groups can look similar and still differ.