A Python framework for Quantification
Go to file
Alejandro Moreo Fernandez 244d1045ce update changelog 2024-04-24 17:07:36 +02:00
.github/workflows Fix the CI by installing the composable dependencies 2024-04-18 10:21:21 +02:00
docs adding wiki documents to the sphinx documentation in order to allow for collaboration 2024-04-24 17:03:57 +02:00
examples updated unit tests 2024-04-16 15:12:22 +02:00
quapy Merge pull request #32 from mirkobunse/devel 2024-04-24 15:26:32 +02:00
.gitignore fixing threshold optimization-based techniques 2024-01-17 09:33:39 +01:00
CHANGE_LOG.txt update changelog 2024-04-24 17:07:36 +02:00
LICENSE license updated 2020-12-15 13:36:24 +01:00
README.md Update README.md 2024-03-06 11:53:43 +01:00
SoBigData.png Add files via upload 2023-06-25 13:29:38 +02:00
TODO.txt merging PR; I have taken this opportunity to refactor some issues I didnt like, including the normalization of prevalence vectors, and improving the documentation here and there 2024-03-19 15:01:42 +01:00
prepare_svmperf.sh cleaning 2020-12-15 15:28:20 +01:00
setup.py Composable methods integrated from qunfold, which is an extra dependency for quapy.method.composable 2024-04-18 10:08:49 +02:00
svm-perf-quantification-ext.patch many aggregative methods added 2020-12-03 18:12:28 +01:00

README.md

QuaPy

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.1.8 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), plese 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
from sklearn.linear_model import LogisticRegression

dataset = qp.datasets.fetch_twitter('semeval16')

# create an "Adjusted Classify & Count" quantifier
model = qp.method.aggregative.ACC(LogisticRegression())
model.fit(dataset.training)

estim_prevalence = model.quantify(dataset.test.instances)
true_prevalence  = dataset.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 Wiki 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).
  • 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 competition (new in v0.1.7!)
  • 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

The developer API documentation is available here.

Check out our Wiki, in which many examples are provided:

Acknowledgments:

SoBigData++