Skip to main content

Quantification Library

Project description

PyPI - Version docs

mlquantify logo

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.

Website: https://luizfernandolj.github.io/mlquantify/


Installation

To install mlquantify, run the following command:

pip install mlquantify

If you only want to update, run the code below:

pip install --upgrade mlquantify

Contents

Section Description
21 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, MAE, NAE, SE, KLD, etc.).
Evaluation Protocols Evaluation protocols used, based on sampling generation (e.g., APP, NPP, etc.)..
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.

from mlquantify.methods import EMQ
from mlquantify.metrics import MAE, NRAE
from mlquantify.utils import get_prev_from_labels

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 = EMQ(RandomForestClassifier())
model.fit(X_train, y_train)

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

#Get the error for the prediction
mae = MAE(real_prevalence, pred_prevalence)
nrae = NRAE(real_prevalence, pred_prevalence)

print(f"Mean Absolute Error -> {mae}")
print(f"Normalized Relative Absolute Error -> {nrae}")

Requirements

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

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.1.25.tar.gz (75.1 kB view details)

Uploaded Source

Built Distribution

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

mlquantify-0.1.25-py3-none-any.whl (92.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mlquantify-0.1.25.tar.gz
  • Upload date:
  • Size: 75.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mlquantify-0.1.25.tar.gz
Algorithm Hash digest
SHA256 2d7441b431683556e7d4ef64d93e13ff7a872ab68e09d9a9cd295603d7d4eef0
MD5 3981b9b45853ef77103ad556dfe07763
BLAKE2b-256 54b7c536a5ede6e81ef555bb27afbc780ef93f3ee86401831f4eb1ae07f60fb1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mlquantify-0.1.25-py3-none-any.whl
  • Upload date:
  • Size: 92.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mlquantify-0.1.25-py3-none-any.whl
Algorithm Hash digest
SHA256 19cebe2c0e5c4c9c7a7ab50cfc8702ef07307dce86e7bb7ecaf17a5675dacd23
MD5 8653d74f2e9eda4c9e7a80f11909eee8
BLAKE2b-256 a8aa906d40901a97834b3c943952a76db7580725700814ea116ee794e777de23

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