Skip to main content

QuaPy

version 0.2.1

QuaPy is an open source framework for quantification (a.k.a. supervised prevalence estimation, or learning to quantify) written in Python.

QuaPy is based on the concept of "data sample", and provides implementations of the most important aspects of the quantification workflow, such as (baseline and advanced) quantification methods, quantification-oriented model selection mechanisms, evaluation measures, and evaluations protocols used for evaluating quantification methods. QuaPy also makes available commonly used datasets, and offers visualization tools for facilitating the analysis and interpretation of the experimental results.

Last updates:

  • Version 0.2.1 is released! major changes can be consulted here.
  • The developer API documentation is available here

Installation

pip install quapy

Cite QuaPy

If you find QuaPy useful (and we hope you will), please consider citing the original paper in your research:

@inproceedings{moreo2021quapy,
  title={QuaPy: a python-based framework for quantification},
  author={Moreo, Alejandro and Esuli, Andrea and Sebastiani, Fabrizio},
  booktitle={Proceedings of the 30th ACM International Conference on Information \& Knowledge Management},
  pages={4534--4543},
  year={2021}
}

A quick example:

The following script fetches a dataset of tweets, trains, applies, and evaluates a quantifier based on the Adjusted Classify & Count quantification method, using, as the evaluation measure, the Mean Absolute Error (MAE) between the predicted and the true class prevalence values of the test set.

import quapy as qp

training, test = qp.datasets.fetch_UCIBinaryDataset("yeast").train_test

# create an "Adjusted Classify & Count" quantifier
model = qp.method.aggregative.ACC()
Xtr, ytr = training.Xy
model.fit(Xtr, ytr)

estim_prevalence = model.predict(test.X)
true_prevalence = test.prevalence()

error = qp.error.mae(true_prevalence, estim_prevalence)
print(f'Mean Absolute Error (MAE)={error:.3f}')

Quantification is useful in scenarios characterized by prior probability shift. In other words, we would be little interested in estimating the class prevalence values of the test set if we could assume the IID assumption to hold, as this prevalence would be roughly equivalent to the class prevalence of the training set. For this reason, any quantification model should be tested across many samples, even ones characterized by class prevalence values different or very different from those found in the training set. QuaPy implements sampling procedures and evaluation protocols that automate this workflow. See the documentation for detailed examples.

Features

  • Implementation of many popular quantification methods (Classify-&-Count and its variants, Expectation Maximization, quantification methods based on structured output learning, HDy, QuaNet, quantification ensembles, among others).
  • Support for uncertainty quantification via bootstrap-based and Bayesian methods, including confidence intervals and simplex-aware confidence regions.
  • Versatile functionality for performing evaluation based on sampling generation protocols (e.g., APP, NPP, etc.).
  • Implementation of most commonly used evaluation metrics (e.g., AE, RAE, NAE, NRAE, SE, KLD, NKLD, etc.).
  • Datasets frequently used in quantification (textual and numeric), including:
    • 32 UCI Machine Learning datasets.
    • 11 Twitter quantification-by-sentiment datasets.
    • 3 product reviews quantification-by-sentiment datasets.
    • 4 tasks from LeQua 2022 competition and 4 tasks from LeQua 2024 competition
    • IFCB for Plancton quantification
  • Native support for binary and single-label multiclass quantification scenarios.
  • Model selection functionality that minimizes quantification-oriented loss functions.
  • Visualization tools for analysing the experimental results.

Requirements

  • scikit-learn, numpy, scipy
  • pytorch (for QuaNet)
  • svmperf patched for quantification (see below)
  • joblib
  • tqdm
  • pandas, xlrd
  • matplotlib

Contributing

In case you want to contribute improvements to quapy, please generate pull request to the "devel" branch.

Documentation

Check out the developer API documentation here.

Check out the Manuals, in which many code examples are provided:

Acknowledgments:

SoBigData++

This work has been supported by the QuaDaSh project "Finanziato dall’Unione europea---Next Generation EU, Missione 4 Componente 2 CUP B53D23026250001".

Release files for QuaPy 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for QuaPy 0.2.2
File Size Uploaded
quapy-0.2.2.tar.gz 165.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for QuaPy 0.2.2
File Interpreter ABI Platform
quapy-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 351.4 kB

Release files / quapy-0.2.2.tar.gz

Download URL quapy-0.2.2.tar.gz
Size 165.4 kB
Tags Source
SHA-256 checksum
How to use checksums
aafffbd752773462d8d14aac0b3d2ffcf21d42ffd463b5e8bdbda48472d326aa
BLAKE2b-256 checksum
How to use checksums
dc702253cda5ab1d2498b811f4ce48ffe687e464316f42f8cfd7114b96434821
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / quapy-0.2.2-py3-none-any.whl

Download URL quapy-0.2.2-py3-none-any.whl
Size 185.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56e73d6b10ed397d01a631fa5c8c8f37aca0794cc86c2cfbfe741cfa3251e7b3
BLAKE2b-256 checksum
How to use checksums
b1906a50b63cb5598e91ff4230423891c347b8dbad993cd70b71378e05e6e6ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page