PyPU
Positive-unlabeled (PU) learning in Python, with a scikit-learn style API.
Status: pre-alpha. The common interface is in place and the methods are being ported. See the roadmap.
In PU learning the training data hold some examples labeled positive and many unlabeled examples, which are a mix of positives and negatives. No example is labeled negative. This happens whenever only one class gets recorded: confirmed frauds, known disease genes, reported misstatements, clicked items.
PyPU collects PU learning methods behind one interface, in the spirit of
PyOD for outlier detection: import a model, fit it on
PU data, and predict on new data.
Installation
pip install pypu-learn
The package is imported as pypu and needs Python 3.11 or newer. (The PyPI name pypu
belongs to an unrelated project, hence pypu-learn.)
Until the first release is on PyPI, install from GitHub:
pip install git+https://github.com/izavits/PyPU.git
Quick start
import numpy as np
from sklearn.datasets import make_classification
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import train_test_split
from pypu.models import NaivePU
# A fully labeled dataset...
X, y = make_classification(n_samples=2000, weights=[0.8], random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=0)
# ...turned into PU data: label half of the training positives, leave the rest unlabeled.
rng = np.random.default_rng(0)
s_train = ((y_train == 1) & (rng.random(len(y_train)) < 0.5)).astype(int)
clf = NaivePU(prior=y_train.mean())
clf.fit(X_train, s_train) # s = 1: labeled positive, s = 0: unlabeled
scores = clf.predict_proba(X_test)[:, 1]
print("ROC AUC:", roc_auc_score(y_test, scores))
Data utilities that turn labeled datasets into PU data in one call are coming in 0.1.0.
The interface
Every model derives from pypu.base.BasePUClassifier and is a scikit-learn estimator, so it
works with clone, Pipeline and GridSearchCV.
| Method | Returns |
|---|---|
fit(X, s) |
The fitted model. s[i] = 1 marks a labeled positive, s[i] = 0 an unlabeled sample. |
predict_proba(X) |
An (n_samples, 2) array; column 1 is the positive-class probability. |
decision_function(X) |
One score per sample; higher means more likely positive. |
predict(X) |
Labels in {0, 1}, thresholding the positive-class probability at threshold_. |
Models that need the class prior π = P(y = 1) take it as a prior parameter.
Methods
| Model | Description | Status |
|---|---|---|
NaivePU |
Treats unlabeled samples as negatives; the usual lower bound | available |
IFPU |
Focal-loss PU risk with gradient boosting | planned (0.1.0) |
IFPNU |
Anomaly detector picks reliable negatives, then a focal PNU risk with gradient boosting | planned (0.1.0) |
SAREM |
EM for labels selected at random (SAR) | planned (0.1.0) |
ElkanNoto, PUBagging |
Classic PU baselines | planned (0.1.0) |
PUHellingerTree, PUHellingerForest |
Hellinger-distance decision trees and forests for PU data | planned (0.2.0) |
NNPU, LBE, PUe, ALMPU |
Neural PU methods (optional PyTorch dependency) | planned (0.3.0) |
Also planned: creating PU data from labeled datasets (uniform SCAR selection, KNN-biased and other SAR selection mechanisms), class-prior estimation, and PU-specific metrics.
Contributing
Contributions are welcome. See CONTRIBUTING.md for the development setup, how to add a model, and the release process. Changes are listed in CHANGELOG.md.
Citing
If you use PyPU in your research, please cite it; GitHub's "Cite this repository" button uses CITATION.cff.
License
PyPU is distributed under the BSD 3-Clause License.
Metadata
Release files for pypu-learn 0.0.1
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 |
|---|---|---|---|---|
| pypu_learn-0.0.1.tar.gz | 14.8 kB | With provenance | Details for pypu_learn-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pypu_learn-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for pypu_learn-0.0.1-py3-none-any.whl |
Total release size: 27.0 kB
Release files / pypu_learn-0.0.1.tar.gz
| Download URL | pypu_learn-0.0.1.tar.gz |
|---|---|
| Size | 14.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b66cbbc23e35c02afc436619b629f2acb28652f0d79f8a24d412922adba27892
|
|
BLAKE2b-256 checksum How to use checksums |
2991fe83d94eaf7b359b55c07aad9c608b1a3d67eb5a2d02548c6dc9d28fb257
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logRelease files / pypu_learn-0.0.1-py3-none-any.whl
| Download URL | pypu_learn-0.0.1-py3-none-any.whl |
|---|---|
| Size | 12.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a9c52776766f1e762dc198d435a00ae0e675a38622cca69021126ded80801ae7
|
|
BLAKE2b-256 checksum How to use checksums |
8554a055d53727d38269774846fdd0fdb8d828f95faff1247e8b697ff0344fb7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logSecurity for pypu-learn 0.0.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pypu_learn-0.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logA 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.