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.1.tar.gz (10.8 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.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: refstat-0.1.1.tar.gz
  • Upload date:
  • Size: 10.8 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.1.tar.gz
Algorithm Hash digest
SHA256 0c4cfe449023c36dd8417ad283f9c76038c8712d363ec96bb0f1c2e1bee1fecb
MD5 4ad2c9425f3059591d9425e760ff92f2
BLAKE2b-256 612449a3f0c17dac724585db19d18d3f92b050c73f79c3abb54a7af120cfe9aa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: refstat-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0eb9d5afaf97d7306ec25f740f23a9314851ad56e3ace3d22cb102c2f08a6a55
MD5 4802a5888d36e233e3f962c8b51c70fd
BLAKE2b-256 096b5ed33ef28258ab249f1c0ff64404ba473f07bb6576b212e49f159f22a67d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

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