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

Metadata

Release files for refstat 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for refstat 0.1.1
File Size Uploaded Provenance Actions
refstat-0.1.1.tar.gz 10.8 kB Without provenance Details for refstat-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for refstat 0.1.1
File Interpreter ABI Platform Actions
refstat-0.1.1-py3-none-any.whl Python 3 none any Details for refstat-0.1.1-py3-none-any.whl

Total release size: 20.6 kB

Release files / refstat-0.1.1.tar.gz

Download URL refstat-0.1.1.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0c4cfe449023c36dd8417ad283f9c76038c8712d363ec96bb0f1c2e1bee1fecb
BLAKE2b-256 checksum
How to use checksums
612449a3f0c17dac724585db19d18d3f92b050c73f79c3abb54a7af120cfe9aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / refstat-0.1.1-py3-none-any.whl

Download URL refstat-0.1.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0eb9d5afaf97d7306ec25f740f23a9314851ad56e3ace3d22cb102c2f08a6a55
BLAKE2b-256 checksum
How to use checksums
096b5ed33ef28258ab249f1c0ff64404ba473f07bb6576b212e49f159f22a67d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for refstat 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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