Skip to main content

English | 中文

PU Learning Toolbox

Positive-Unlabeled learning in Python -- sklearn-compatible API, 17 research paper methods, SCAR & SAR support.

Python Status License

Features

  • 17 algorithms from recent PU learning research, all native clean-room implementations (method cards)
  • sklearn-compatible API -- fit(X, y) / predict(X) / decision_function(X), works with pipelines and cross-validation
  • SCAR & SAR -- constant and instance-dependent labeling mechanisms, with a data simulator
  • Data profiling + recommender -- automatic quality checks, SCAR/SAR evidence, and a 7-dimension scoring recommender that picks the method for your data
  • Auditable pipeline -- one-call PUPipeline (profile -> prior -> train -> PU-stratified CV -> evaluate) plus structured diagnostic reports and prior/propensity sensitivity analysis
  • CLI -- pu-toolbox turns the whole pipeline into terminal commands

Quick Start

pip install pu-toolbox                # core dependencies (Python >= 3.10)
pip install "pu-toolbox[torch]"       # + PyTorch-based methods (nnPU, Dist-PU, Self-PU, ...)

Installation environments

Any Python interpreter >= 3.10 works: the package is a pure-Python universal wheel with no compiled extensions, so the interpreter source does not matter. Notes per environment:

  • venv / uv (recommended): standard isolated environments, nothing special.
  • System Python (python.org / Ubuntu / Homebrew): must be >= 3.10. Ubuntu 22.04+ and Debian 12+ block pip install into the system environment (PEP 668) -- create a venv instead.
  • Anaconda / Miniconda: pip install pu-toolbox inside a conda env (the package is PyPI-only; conda install will not find it). If you already installed torch via conda, a plain pip install pu-toolbox (without the [torch] extra) still enables the PyTorch-based methods -- torch is an optional dependency loaded lazily.

Hello World

import numpy as np
from pu_toolbox.preprocessing import make_sar_dataset
from pu_toolbox import PUPipeline

# Synthetic PU data: some positives are labeled (1), rest are unlabeled (0)
X, y_pu, y_true, _ = make_sar_dataset(
    n_samples=1000, n_features=8, class_prior=0.3, random_state=42,
)

# One call: profile -> class prior -> train -> PU-stratified CV -> evaluate
report = PUPipeline().fit_evaluate(X, y_pu, y_true=y_true)
print(report.summary())

Full docs (Chinese): docs/README.md. More runnable examples: examples/minimal/.

Command Line

The pu-toolbox console command wraps the full pipeline. Full guide: docs/user/howto/cli.md.

# 1. Generate SCAR demo data (X.csv / y_pu.csv / y_true.csv)
pu-toolbox make-demo-data --out-dir demo/ --n 200 --seed 42

# 2. One-shot full pipeline run (auto mode picks the algorithm)
pu-toolbox run --data demo/X.csv --labels demo/y_pu.csv --out-dir results/

# 3. Inspect results
#    results/report.md     full Markdown report
#    results/report.json   strict JSON (no NaN), machine-readable

Documentation

Docs are split by audience; the full index is docs/README.md.

Entry Content
docs/user/quickstart.md 5-minute start (CLI + Python)
docs/user/concepts/ PU problem, SCAR/SAR, method selection
docs/user/howto/ Task guides: simulation, profiling, pipeline, CLI, reports, sensitivity
docs/user/reference/api.md Precise API contract
docs/dev/ Contributor docs: architecture, structure, roadmap, compatibility
docs/research/method_cards/ Per-paper research cards

AI workflow skill

pu-workflow (Agent Skills open standard) drives the full PU analysis workflow — profiling, assumption diagnosis, method recommendation, training, and result interpretation — from natural language. Loaded natively by Claude Code / Cursor (.claude/skills/) and Codex / Gemini CLI / Windsurf (.agents/skills/).

Development

git clone https://github.com/shuidisjtu/pu-learning-toolbox.git
cd pu-learning-toolbox
pip install -e ".[dev,torch]"   # development install
uv run pytest tests/ -v -m "not slow and not e2e"   # fast tests (e2e runs nightly)
uv run ruff check pu_toolbox/               # lint
uv run ruff format --check pu_toolbox/      # format check

# Quality gates
uv run python scripts/check_test_quality.py
uv run python scripts/check_doc_links.py
uv run python scripts/check_project_metadata.py
uv run python scripts/check_math_rendering.py
uv run python scripts/check_skill_sync.py
uv run python scripts/check_format.py        # ruff check + format --check (full scope)

See CONTRIBUTING.md for contribution guidelines.

License

MIT

Download files

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

Source Distribution

pu_toolbox-1.1.1.tar.gz (868.2 kB view details)

Uploaded Source

Built Distribution

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

pu_toolbox-1.1.1-py3-none-any.whl (191.3 kB view details)

Uploaded Python 3

File details

Details for the file pu_toolbox-1.1.1.tar.gz.

File metadata

  • Download URL: pu_toolbox-1.1.1.tar.gz
  • Upload date:
  • Size: 868.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pu_toolbox-1.1.1.tar.gz
Algorithm Hash digest
SHA256 79bfd499ce0ba43c5646a8a5009bebe5df01a29e6f24da3d18abe21bc24648e2
MD5 1cfd3b59fd694d2e583fcc5d82f1365f
BLAKE2b-256 f741a36f3f9f0457ea03aa00b500979b0203159bc33bd4764853ef6312636fe7

See more details on using hashes here.

File details

Details for the file pu_toolbox-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: pu_toolbox-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 191.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pu_toolbox-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a1a0bb6d79642975f8f33f6ebc164f17e067c9145bf32e5043d140b6a22301f
MD5 297980ce57004c28c3ab5a8b9e842d23
BLAKE2b-256 df2d782905e97307a665fe2b20fd0127268dfbcc7f78df4ee107fd77ead1ff80

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