Skip to main content

Outlier detection for semi-normal distributions using the mirroring technique

Project description

mirror-mirror

Outlier detection for semi-normal distributions.

Most outlier detection methods assume your data is fully normal. But what if it's only half normal — a clear peak with one meaningful tail? mirror-mirror handles exactly that.

How it works

  1. Find the peak of your distribution (via KDE or max value)
  2. Take the tail-side data (everything at or below the peak)
  3. Mirror it across the peak to create a synthetic full normal distribution
  4. Compute mean and std of the synthetic distribution
  5. Flag anything below mean − threshold × std as an outlier

Installation

pip install mirror-mirror

Quick start

from mirror_mirror import find_outliers

# Example: exam scores — most students score high, outliers at the low end
scores = [95, 97, 92, 88, 91, 99, 100, 94, 96, 72, 65, 55, 48]

result = find_outliers(scores, method="mode", threshold=2)

print(result["outliers"])   # array([48])
print(result["cutoff"])     # e.g. 62.4

API

find_outliers(data, method="mode", threshold=2.0)
Parameter Type Default Description
data list / np.ndarray / pd.Series required 1-D numeric data. NaNs are ignored.
method "mode" or "max" "mode" How to locate the peak of the distribution.
threshold float 2.0 Sigmas below the mirror mean to cut off at.

Return value

A dict with:

Key Description
outliers np.ndarray of values identified as outliers
cutoff The threshold value — points below this are outliers
mirror_mean Mean of the synthetic mirrored distribution
mirror_std Std dev of the synthetic mirrored distribution

method parameter

  • "mode" (default) — uses KDE to find the most-dense region of the data as the peak. Best for real-world, noisy data.
  • "max" — uses the maximum value as the peak. Useful when your data is naturally bounded at the top (e.g. a 100-point exam, property values with a known ceiling).

threshold parameter

Controls sensitivity. A value of 2.0 means any point more than 2 standard deviations below the mirror mean is flagged. Increase for fewer (more extreme) outliers; decrease for more.

When to use this

mirror-mirror works well when your data:

  • Has a clear, single peak
  • Has one natural tail (skewed left or right)
  • Is not bimodal or uniformly distributed

Examples: exam scores, property values, response times, sensor readings with a hard ceiling.

License

MIT

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

my_sire_that_is_an_outlier-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

my_sire_that_is_an_outlier-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for my_sire_that_is_an_outlier-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8a1ee962cd75ff572a1910c4ce2a2106a4dc37d7fbfe5bd6a40a089a1f962789
MD5 70f51abafe10a9d7c34ade8d91d5bb3e
BLAKE2b-256 397ef6cf06b17e77639c0de64889b66b07e886fe2217a5b208fe60b5c1ba75dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for my_sire_that_is_an_outlier-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5c5d31f2066d9ba8b7bb33be2ed66482b699e15ee780bb7bb9689b6207d4174
MD5 32599941e1b46c776a01955acd46ead7
BLAKE2b-256 bc5b3a007649e1802c8e6695eac4050e858aa9e1273204d04460ed3212e472a0

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