Skip to main content

refstat

Distance-based deviation scoring, reference standardisation, and temporal pattern decomposition, built for the common case where you only have a small trusted reference set (3-10 observations), not the ~100s or ~1000s most tooling assumes.

Install

pip install refstat

What's here

  • refstat.scorers : Mahalanobis distance (Ledoit-Wolf shrinkage, stable down to n=3), nearest-centroid distance, a composite scoring helper, and leave-one-out calibration (reference_composite_range, classify_against_reference) so a score is interpreted against your specific reference set, not a fixed threshold
  • refstat.baseline : build reference statistics from a small set of observations and standardise new observations against them
  • refstat.dtw_patterns : separates "started late," "took longer once started but moved correctly," and "moved differently" in repeated signal comparisons, using Sakoe-Chiba banded DTW

Example

import numpy as np
from refstat.scorers import MahalanobisScorer, reference_composite_range, classify_against_reference

reference = np.array([[1.0, 2.1], [1.1, 1.9], [0.9, 2.0]])
scorer = MahalanobisScorer()
scorer.fit(reference)

score = scorer.score(np.array([5.0, 5.0]))
ref_low, ref_high = reference_composite_range(reference)
print(classify_against_reference(score, ref_low, ref_high))  # within_range / borderline / above_range

See examples/reference_screening_example.py for a full workflow combining reference standardisation, composite scoring, and calibrated interpretation.

Motivation

Most anomaly detection tooling needs enough data to estimate density or covariance reliably. When you only have a handful of trusted reference points, those methods either fail outright or give unstable results. This targets that regime specifically:

  • Per-unit quality control : score a newly calibrated machine or unit against its own 3-5 test runs, not a factory-wide spec
  • Personal baseline monitoring : score a new reading against one person's own recent history, not a population norm that may not fit them
  • New-deployment anomaly detection : a new sensor or site needs to start flagging problems from day one, before weeks of data exist to build a standard model
  • Small-cohort research : compare a new case against a small reference cohort when a large population dataset doesn't exist for the condition being studied

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

refstat-0.1.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

refstat-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file refstat-0.1.0.tar.gz.

File metadata

  • Download URL: refstat-0.1.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for refstat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7744e89bbc4adca8be22a08e731912e5612a3ba63bc9ea30cf95e35e00182bfc
MD5 0605a7688239fd13218c882595493e77
BLAKE2b-256 76683ba82afee97daccea0e4f6e0ac2c5030b794c0a64f2a29b3cb21cf5195e3

See more details on using hashes here.

File details

Details for the file refstat-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: refstat-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for refstat-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0f42939fc9e16db077a5108a731fd448a134ad58a25c890644f088628398caf
MD5 7e6db43c2312a187a1b492738cf45af2
BLAKE2b-256 40536d9de3344a4f1932ca7b81aee062dfc0342d2cba551db899278d23662d5d

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page