Pre-model data leakage scanner for ML datasets
Project description
Overview
LeakProfiler is a lightweight inspection tool designed to detect potential data leakage risks in machine learning datasets before model training.
The system acts as a pre-model safety scanner, analyzing features and identifying suspicious columns that may artificially inflate model performance.
LeakProfiler does not perform data cleaning, feature engineering, or modeling. Its sole responsibility is to detect leakage patterns and generate warnings to support safer ML workflows.
Features (Version 1.0.0a1 - Alpha)
- Dataset Loading & Profiling: Ingests a CSV and profiles its structure.
- Leakage Detectors:
- Identifier Column Detection
- Duplicate Row Detection
- Group Leakage Detection
- Temporal Leakage Detection
- High Correlation Detection with Target
- High Feature Importance Detection
- Rich Reporting: Color-coded findings summary and dashboard.
- Analysis Confidence: High/Medium/Low score with percentage.
- Analysis Stability: Warns for very small datasets and high-dimensional instability.
- Validation Advisory: Recommends split strategy (
TimeSeriesSplit,GroupKFold, or standard split). - Next Actions Checklist: Deduplicated, priority-based (
P1/P2/P3) checklist with reasons. - Cross-Detector Reasoning: Adds composite findings by combining evidence across detectors (reported as
Cross-Detectorcategory). - Benign Pattern Detection: Adds conservative, explainable low-risk contextual findings (
Benign-Pattern) for likely non-leakage signals. - Principled Advisory Engine: Uses calibrated evidence scoring, overlap de-duplication, uncertainty estimation, and explainable rationale.
- Config-Driven Advisory Weights: Advisory scoring uses explicit, tunable config for severity/category weights, thresholds, bonuses, and penalties.
- Per-Finding Confidence: Each finding gets a confidence estimate that influences contribution to overall risk.
- JSON Export: Export report + checklist to stdout, file, or Python payload.
- Notebook Export Button (Optional): In-notebook button to export JSON.
Cross-Detector Reasoning
After individual detectors run, LeakProfiler performs a second-pass inference step to identify multi-signal risks.
Current cross-detector rules include:
- Correlation + Feature Importance overlap on the same feature → Cross-detector proxy leakage consensus.
- Identifier + Group Leakage overlap on the same column/entity key → Cross-detector entity memorization risk.
- Temporal signals + highly predictive feature overlap → Cross-detector temporal proxy risk.
- Unstable analysis conditions + strong statistical findings → Cross-detector confidence caution.
These composite findings are integrated into:
- Findings summary table
- Risk score/dashboard
- Validation advisory and checklist
- JSON export payload
Benign Pattern Detection
After base detectors and cross-detector reasoning, LeakProfiler runs a conservative benign-pattern pass to identify signals that may look suspicious statistically but are often operationally normal.
Design principles:
- Do not suppress risk findings: benign findings are additive context, not replacements.
- Exclude from risk score:
Benign-Patternfindings are not counted in leakage severity totals. - Conservative edge-case handling: benign tags are blocked when strong corroborating risk signals exist.
Current benign rules (tuned):
- Sparse duplicate noise: duplicate ratio must be extremely small (adaptive threshold by dataset size).
- Isolated strong predictor: allowed only when no corroborating correlation/group/temporal/identifier risk exists, with stable + high-confidence analysis and no HIGH-severity findings.
- Weak temporal structure: only moderate temporal signal without high autocorrelation, regular spacing, high timestamp uniqueness, group risk, or temporal cross-detector overlap.
Output behavior:
- Dashboard now includes a
Benign Findingscount. - Benign findings appear in the findings table as category
Benign-Pattern. - JSON summary includes
benign_findings.
Principled Advisory Engine
LeakProfiler separates risk estimation from action recommendation:
- Risk estimation uses weighted evidence from findings (severity + category + per-finding confidence), then applies:
- corroboration bonus when multiple independent signals align,
- overlap penalties to reduce double-counting between correlated detectors.
- Configuration-driven policy keeps thresholds and weights explicit and tunable.
- Strict HIGH gate:
HIGHrisk is only emitted when corroboration and confidence gates both pass; otherwise it is downgraded toMODERATE. - Uncertainty estimation combines confidence level, analysis stability, and evidence sufficiency.
- Action recommendation builds a deduplicated checklist from actionable findings only.
Explainability outputs:
- Dashboard includes
Risk LevelandAdvisory Uncertainty. - Advisory panel includes an
Advisory Basissection with top contributors, bonuses/penalties, and calibrated score. - JSON summary includes
risk_level,uncertainty, andrisk_rationale.
Installation
pip install -r requirements.txt
Optional notebook UI dependencies (only needed for show_export_button=True):
pip install ipywidgets ipython
Install from PyPI (after publish):
pip install leakprofiler
Distribution (PyPI)
Build artifacts:
python -m pip install --upgrade build twine
python -m build
Validate package metadata:
python -m twine check dist/*
Upload to TestPyPI:
python -m twine upload --repository testpypi dist/*
Upload to PyPI:
python -m twine upload dist/*
The package exposes:
- CLI command:
leakprofiler - Python API:
from LeakProfiler import run_leakprofiler
Usage
from LeakProfiler import run_leakprofiler
run_leakprofiler("dataset.csv", target_column="TargetColumn")
# Print JSON to stdout
run_leakprofiler("dataset.csv", target_column="TargetColumn", json_stdout=True)
# Write JSON to file
run_leakprofiler("dataset.csv", target_column="TargetColumn", json_output_path="leakprofiler_report.json")
# Return payload as dict
payload = run_leakprofiler("dataset.csv", target_column="TargetColumn", return_payload=True)
# Show export button in a notebook
run_leakprofiler(
"dataset.csv",
target_column="TargetColumn",
show_export_button=True,
export_button_path="leakprofiler_report.json"
)
# Backward compatibility: importing from `leakguard` and calling `run_leakguard(...)` is still supported.
CLI usage:
python LeakProfiler.py --file dataset.csv --target TargetColumn --json
python LeakProfiler.py --file dataset.csv --target TargetColumn --json-path leakprofiler_report.json
run_leakprofiler Parameters
file_path(str, required): CSV path.target_column(str, required): target column name.json_output_path(str, optional): write JSON report to file.json_stdout(bool, optional): print JSON report to stdout.return_payload(bool, optional): return JSON payload as a Python dict.show_export_button(bool, optional): show Jupyter export button under output.export_button_path(str, optional): output file path used by export button.
Project Objective
LeakProfiler demonstrates understanding of:
- Data leakage failure modes in machine learning.
- Structural and statistical dataset analysis.
- Data-centric ML safety practices.
- Modular and clear engineering design.
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 leakprofiler-1.0.0a1.tar.gz.
File metadata
- Download URL: leakprofiler-1.0.0a1.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd49e25e5e5690a7afd39f464cc0c4f8058cd874a6e5aa9f3e9c477998817e39
|
|
| MD5 |
087b4eccb6d9f6e3da156a76c6abef3e
|
|
| BLAKE2b-256 |
c9b46aa371c10be1d4e4d3af552acb53031dfffe70adbf823e81ca77f2ad8af5
|
File details
Details for the file leakprofiler-1.0.0a1-py3-none-any.whl.
File metadata
- Download URL: leakprofiler-1.0.0a1-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e68ac06f8b5f273d34a15a8f1fe38fab7f0ae87625b4942e3ee6fb14afdeebc
|
|
| MD5 |
97cd663945918055a9d77d399cca7e0d
|
|
| BLAKE2b-256 |
0bea4e1c0b02c2ac2379cbb44d32783c34fad76c79a8539871a38c8342d03c29
|