A Python library for detecting anomalous subgroups in data using subset scanning techniques
Project description
Anomalous Subgroup Detection
A Python library for detecting anomalous subgroups in data using subset scanning techniques. This implementation is inspired by the paper "Subset Scanning Over Neural Network Activations" but generalized for broader applications.
Overview
This library implements a statistical approach to detect anomalous subgroups in data by scanning through potential subsets defined by combinations of feature values. It uses likelihood ratio tests to identify subgroups that significantly deviate from the expected distribution.
Key features:
- Supports both Gaussian (continuous) and Bernoulli (binary) data distributions
- Identifies statistically significant anomalous subgroups
- Provides p-values through permutation testing
- Handles categorical features for subgroup definition
- Configurable search depth for feature combinations
Installation
pip install anomalous-subgroup-detection
Quick Start
from anomalous_subgroup_detection import SubsetScanDetector
# Initialize detector
detector = SubsetScanDetector(
statistic_type='gaussian', # or 'bernoulli'
features=['feature_A', 'feature_B'],
max_combination_size=2,
num_permutations=100
)
# Run the scan
detector.fit_and_scan(data, target_column='amount')
# Get results
results = detector.get_results()
print(f"Best Score: {results['best_score']}")
print(f"Best Subset: {results['best_subset_definition']}")
print(f"P-value: {results['p_value']}")
Use Cases
- Fraud detection in financial transactions
- Anomaly detection in healthcare data
- Quality control in manufacturing
- Security monitoring
- Any scenario where you need to identify unusual patterns in subgroups of data
How It Works
- The detector scans through potential subgroups defined by combinations of feature values
- For each subgroup, it calculates a likelihood ratio test statistic comparing:
- H0: The subgroup follows the overall data distribution
- H1: The subgroup follows a different distribution
- The subgroup with the highest score is identified as the most anomalous
- Statistical significance is assessed through permutation testing
Documentation
For detailed documentation and examples, see the examples directory.
License
MIT License
Reference
If you use this software in your research, please reference:
@article{speakman2018subset,
title={Subset Scanning Over Neural Network Activations},
author={Speakman, Skyler and Sridharan, Srihari and Remy, Sekou and Weldemariam, Komminist and McFowland III, Edward},
journal={arXiv preprint arXiv:1810.08676},
year={2018}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anomalous_subgroup_detection-0.1.1.tar.gz.
File metadata
- Download URL: anomalous_subgroup_detection-0.1.1.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e4009ff43b0ab79c720af6714197497db40ee87ac3b9060563a2a488e839326
|
|
| MD5 |
75c0de80d9651e5f01cc6ec9f1f60da8
|
|
| BLAKE2b-256 |
1d119b020163742f0c374d24b9ddb0d539e4a298b4dbf77f5d6380cd1196dc98
|
File details
Details for the file anomalous_subgroup_detection-0.1.1-py3-none-any.whl.
File metadata
- Download URL: anomalous_subgroup_detection-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d752da936d96aadb6745d1089802fead3bae93462494b2bb543cf328b44dde6
|
|
| MD5 |
f7b51613a4ac7449015c0484f818989a
|
|
| BLAKE2b-256 |
eb1d6363a2ebb3695ddbff2e6dbd6abbf2390199b1f8fb56e7b984e588612f7d
|