Skip to main content

Quantification Library

Project description

MLQuantify

A Python Package for Quantification


mlquantify is a Python library for quantification, also known as supervised prevalence estimation, designed to estimate the distribution of classes within datasets. It offers a range of tools for various quantification methods, model selection tailored for quantification tasks, evaluation metrics, and protocols to assess quantification performance. Additionally, mlquantify includes popular datasets and visualization tools to help analyze and interpret results.


Latest Release

  • Version 0.0.1: Inicial beta version. For a detailed list of changes, check the changelog.
  • In case you need any help, refer to the wiki.
  • Explore the API documentation for detailed developer information.
  • See also the library in the pypi site in pypi mlquantify

Installation

To install mlquantify, run the following command:

pip install mlquantify

Contents

Section Description
Quantification Methods Methods for quantification, such as classify & Count Correct methods, Threshold Optimization, Mixture Models and more.
Dynamic class management All methods are dynamic, and handles multiclass and binary problems, in case of binary it makes One-Vs-All (OVA) automatically.
Model Selection Criteria and processes used to select the best model, such as grid-search for the case of quantification
Evaluation Metrics Specific metrics used to evaluate quantification performance, (e.g., AE, BIAS, NAE, SE, KLD, etc.).
Evaluation Protocols Evaluation protocols used, based on sampling generation (e.g., APP, NPP, etc.)..
Plotting Results Tools and techniques used to visualize results, such as the protocol results.
Comprehensive Documentation Complete documentation of the project, including code, data, and results.

Quick example:

This code first loads the breast cancer dataset from sklearn, which is then split into training and testing sets. It uses the Expectation Maximisation Quantifier (EMQ) with a RandomForest classifier to predict class prevalence. After training the model, it evaluates performance by calculating and printing the absolute error and bias between the real and predicted prevalences.

import mlquantify as mq
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split

# Loading dataset from sklearn
features, target = load_breast_cancer(return_X_y=True)

#Splitting into train and test
X_train, X_test, y_train, y_test = train_test_split(features, target, test_size=0.3)

#Create the model, here it is the Expectation Maximisation Quantifier (EMQ) with a classifier
model = mq.methods.EMQ(RandomForestClassifier())
model.fit(X_train, y_train)

#Predict the class prevalence for X_test
pred_prevalence = model.predict(X_test)
real_prevalence = mq.utils.get_real_prev(y_test)

#Get the error for the prediction
ae = mq.evaluation.absolute_error(real_prevalence, pred_prevalence)
bias = mq.evaluation.bias(real_prevalence, pred_prevalence)

print(f"Mean Squared Error (MSE) -> {ae:.4f}")
print(f"Bias -> {bias}")

Requirements

  • Scikit-learn
  • pandas
  • numpy
  • joblib
  • tqdm
  • matplotlib
  • xlrd

Documentation

API is avaliable here

See the References in the pdf below

...

Project details


Download files

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

Source Distribution

mlquantify-0.0.11.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

mlquantify-0.0.11-py3-none-any.whl (56.1 kB view details)

Uploaded Python 3

File details

Details for the file mlquantify-0.0.11.tar.gz.

File metadata

  • Download URL: mlquantify-0.0.11.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for mlquantify-0.0.11.tar.gz
Algorithm Hash digest
SHA256 ce8e73cd442c43083733aeed0981ae2d1ad2eb43940836cd52e6d03c5d664c57
MD5 1be489934ea684a5cbf34dc991eb2055
BLAKE2b-256 221eff036124f74cbc926548937f15320c87cea1a33cb7ef8f74abd0a4c03ac3

See more details on using hashes here.

File details

Details for the file mlquantify-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: mlquantify-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 56.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for mlquantify-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 c86b6132f224d5c541e8ae883a58eed8badf5d32ab1cbfd4850a611a9e55c2c9
MD5 abe0705ca1c1ea9449d7a7109f9acd31
BLAKE2b-256 7790c5ccd469f7568a037496da86b61b7333a3d0339098a9384f661d34ca3099

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page