Skip to content
codesphere-uPublic

About

Deterministic scientific ML dataset leakage auditor: exact duplicates, group-ID contamination, temporal look-ahead/embargo violations, Haversine spatial proximity leakage, and target-proxy detection.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

leakguard

CI License: MIT Python 3.11+ Zero Dependencies

Deterministic scientific ML dataset leakage auditor: exact row duplicates, group-ID contamination, temporal look-ahead/embargo violations, Haversine spatial proximity leakage, and target-proxy detection.

  • Mission Domain: Scientific Research & Reproducible ML
  • Stack: Pure Python 3.11+ (zero runtime third-party dependencies, mypy --strict, ruff, pytest)
  • Maintainer: Codesphere Innovations (U) Limited (codesphere-u)

Problem Solved

Peer-reviewed ML models in healthcare, climate, agriculture, and finance are routinely invalidated by subtle train/test leakage (shared patients/farms, shuffled timestamps, nearby spatial clusters, or post-outcome target proxies) that schema validators miss.

Key Features

  • LEAK-001 Canonical SHA-256 exact duplicate feature row detection across train and test splits.
  • LEAK-002 Entity / Group-ID overlap detection (patient_id, farm_id, household_id).
  • LEAK-003 Chronological look-ahead and autocorrelation embargo window enforcement.
  • LEAK-004 Great-circle WGS84 Haversine spatial-proximity buffer verification (km).
  • LEAK-005 Pearson target-proxy correlation scan & LEAK-006 order-of-magnitude SI/imperial unit-shift warning.

Architecture Overview

flowchart LR
  A[train.csv & test.csv] --> B[auditor.py]
  B --> C[LEAK-001/002<br/>Row Hash & Group Overlap]
  B --> D[LEAK-003/004<br/>Temporal Embargo & Haversine]
  B --> E[LEAK-005/006<br/>Target Proxy & Unit Shift]
  C & D & E --> F[CI Exit Code 0 / 2 + JSON]
Loading

See docs/architecture.md for module-level design details.

Installation

git clone https://github.com/codesphere-u/leakguard.git
cd leakguard
uv sync --extra dev

Or install in editable mode with standard pip:

pip install -e ".[dev]"

Quick Start (CLI)

leakguard audit train.csv test.csv --target outcome --group patient_id --time ts --lat lat --lon lon --embargo-hours 24

Quick Start (Python API)

from leakguard import audit_split

rep = audit_split([{"id": "A", "x": 1, "y": 0}], [{"id": "A", "x": 1, "y": 0}], group_col="id", target_col="y")
assert not rep.passed

Testing & Quality Gates

uv run ruff check src tests
uv run mypy src
uv run pytest -v

Security, Contributing & Roadmap

License

MIT License — see LICENSE.

Support & Contact

Open an issue on GitHub Issues or contact [email protected].

About

Deterministic scientific ML dataset leakage auditor: exact duplicates, group-ID contamination, temporal look-ahead/embargo violations, Haversine spatial proximity leakage, and target-proxy detection.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages