phenome-outlier-analysis
OutlierDetector Class Documentation
Overview
The OutlierDetector class is designed for detecting outliers in datasets using various normalization methods. It supports both context-specific and global outlier detection strategies, making it versatile for different types of data analysis.
Class Initialization
OutlierDetector(df, analyte_columns, segment_columns=['sex'])
Parameters:
df(pandas.DataFrame): The input DataFrame containing the data to be analyzed.analyte_columns(list): A list of column names to be analyzed for outliers.segment_columns(list, optional): A list of column names used for segmentation in context-specific outlier detection. Defaults to ['sex'].
Main Methods
1. perform_outlier_detection
perform_outlier_detection(lower_percentile=0.01, upper_percentile=0.99, method='double_mad', take_log=False)
This is the primary method to perform outlier detection on the given DataFrame.
Parameters:
lower_percentile(float): Lower percentile for cutoff calculation. Default is 0.01.upper_percentile(float): Upper percentile for cutoff calculation. Default is 0.99.method(str): Normalization method. Can be 'double_mad' or 'zscore'. Default is 'double_mad'.take_log(bool): Whether to apply log transformation before normalization. Default is False.
Returns:
A tuple containing two dictionaries:
- Context-specific results
- Super-global results
2. context_specific_outlier_detection
context_specific_outlier_detection(method='double_mad', take_log=False)
Performs context-specific outlier detection by segmenting the DataFrame based on the segment_columns.
3. super_global_outlier_detection
super_global_outlier_detection(method='double_mad', take_log=False)
Evaluates outliers on a global scale, considering all data points together.
Helper Methods
calculate_double_mad
Calculates left and right Median Absolute Deviations (MADs) from the median.
normalize_series
Normalizes a series using the specified method (double_mad or zscore).
calculate_percentile_cutoffs
Calculates global percentile cutoffs based on the specified columns of a DataFrame.
create_binary_matrix
Creates a binary matrix indicating outliers based on specified cutoffs.
normalize_dataframe
Normalizes specified columns in a DataFrame.
detect_outliers
Detects outliers in the specified columns of a DataFrame.
get_global_cutoffs
Gets global cutoffs for outlier detection.
Usage Example
import pandas as pd
from outlier_detection import OutlierDetector
# Load your data
df = pd.read_csv('your_data.csv')
# Define columns
analyte_columns = ['column1', 'column2', 'column3']
segment_columns = ['sex', 'age_group']
# Create OutlierDetector instance
detector = OutlierDetector(df, analyte_columns, segment_columns)
# Perform outlier detection
context_results, global_results = detector.perform_outlier_detection(
lower_percentile=0.01,
upper_percentile=0.99,
method='double_mad',
take_log=True
)
# Analyze results
for (segment, value), result in context_results.items():
print(f"Outliers for {segment}={value}:")
print(result['binary_matrix'].sum())
print("Global outliers:")
print(global_results[('global', 'global')]['binary_matrix'].sum())
Notes
- The class uses logging to provide information and warnings during the outlier detection process.
- The
tqdmlibrary is used to show progress bars for long-running operations. - The class can handle both context-specific (segmented) and global outlier detection.
- Two normalization methods are supported: 'double_mad' (double Median Absolute Deviation) and 'zscore'.
- Log transformation can be applied before normalization if needed.
Metadata
Release files for phenome-outlier-analysis 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| phenome_outlier_analysis-0.1.0.tar.gz | 5.4 kB | Without provenance | Details for phenome_outlier_analysis-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| phenome_outlier_analysis-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for phenome_outlier_analysis-0.1.0-py3-none-any.whl |
Total release size: 12.2 kB
Release files / phenome_outlier_analysis-0.1.0.tar.gz
| Download URL | phenome_outlier_analysis-0.1.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fadd5fbd5befc06f2e8f97c232dd3ae003b7da4afc58eded04181cda165fb0b5
|
|
BLAKE2b-256 checksum How to use checksums |
da67a4edc5c168a8fdd90d80c40708c66ad12443a9441cab2fc80458031d38ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / phenome_outlier_analysis-0.1.0-py3-none-any.whl
| Download URL | phenome_outlier_analysis-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37fce37970dc8e0aa6de056acba5719c8c578750b53aa975d0091dbbaf309f78
|
|
BLAKE2b-256 checksum How to use checksums |
564b9ccddb69fcf58ca09bc5de16dfd9d7328efdb4afcd16c6a18df799300d5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Security for phenome-outlier-analysis 0.1.0
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.