Skip to main content

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

  1. The detector scans through potential subgroups defined by combinations of feature values
  2. 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
  3. The subgroup with the highest score is identified as the most anomalous
  4. Statistical significance is assessed through permutation testing

Documentation

For detailed documentation and examples, see the examples directory.

License

MIT License

Citation

If you use this software in your research, please cite:

@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


Download files

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

Source Distribution

anomalous_subgroup_detection-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

anomalous_subgroup_detection-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for anomalous_subgroup_detection-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ab41de8af11cecc91880c5f50233b3d4bdeb655e3043090cd3e41967497a2bbb
MD5 e2a022ee182c1f6fb935733368fb5fb6
BLAKE2b-256 ed3b2e0af699308126ccc2c8fc2f2790011b1f728164a7f625df7f60877219a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for anomalous_subgroup_detection-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8050496063ac97a270e47b64e6bca7ee6feaa66683fa3bd603f6e3526982ec69
MD5 3f025304b758f873a99ef308c5c3212d
BLAKE2b-256 785c9da01900c0c27e2901bc96e78b2382a5e4ec030a71d2acd08878fcfa6d1d

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