Skip to main content

Weighted MCC: Robust Multiclass Metrics

Weighted MCC is a Python package that implements robust performance metrics for binary and multiclass classification tasks where individual observations have different importance weights.

Based on the paper describing Weighted Matthews Correlation Coefficient (MCC), this package provides a mathematically sound way to evaluate classifiers in high-stakes domains like medical imaging (segmentation) and autonomous driving, where some errors are costlier than others.

Features

  • Weighted Binary MCC: Calculate MCC for binary tasks with per-sample weights.
  • Multiclass Extensions:
    • ECC (Extended Correlation Coefficient): A robust multiclass generalization of MCC.
    • MPC (Multivariate Pearson Correlation): Variants (MPC1, MPC2) derived from covariance matrix theory.
  • Robustness Analysis:
    • Compute theoretical upper bounds on metric stability given weight perturbations ($\epsilon$).
    • Theoretically proven stability ensures metrics are not brittle to small weight changes.
  • Efficient Implementation: Vectorized operations using NumPy for high performance on large datasets.

Installation

pip install weighted_mcc

Usage

Binary Classification

import numpy as np
from weighted_mcc import weighted_mcc

y_true = np.array([1, 0, 1, 1, 0])
y_pred = np.array([1, 0, 0, 1, 1])
weights = np.array([2.0, 1.0, 5.0, 1.0, 1.0]) # 3rd sample is critical

# Calculate Weighted MCC
score = weighted_mcc(y_true, y_pred, weights)
print(f"Weighted MCC: {score:.4f}")

Multiclass Classification

For multiclass, inputs should generally be one-hot encoded for the mathematical functions, or use helper utilities if provided (check documentation).

import numpy as np
from weighted_mcc import extended_corr_coef, mpc_trace_ratio

# Example: 3 classes, 4 samples
y_true = np.array([[1,0,0], [0,1,0], [0,0,1], [1,0,0]])
y_pred = np.array([[1,0,0], [0,0,1], [0,0,1], [0,1,0]])
weights = np.array([1.0, 1.0, 2.0, 1.0])

# Extended Correlation Coefficient
ecc = extended_corr_coef(y_true, y_pred, weights)
print(f"ECC: {ecc:.4f}")

# Multivariate Pearson Correlation (Trace Ratio)
mpc1 = mpc_trace_ratio(y_true, y_pred, weights)
print(f"MPC1: {mpc1:.4f}")

Robustness Check

Verify if your metric score is stable under potential weight noise (e.g., if weights are subjective).

from weighted_mcc import calculate_multiclass_stability_bound

epsilon = 0.01 # Max potential deviation in weights
bound = calculate_multiclass_stability_bound(y_true, y_pred, weights, epsilon, metric_type='ECC')

print(f"Score could vary by at most ±{bound:.4f} given epsilon={epsilon}")

Hardware Requirements

  • Minimum: Modern CPU, 8GB RAM (small datasets).
  • Recommended: Multi-core CPU with AVX2, 16GB+ RAM for large image segmentation tasks.

References

This project incorporates research from the following paper:

  • Weighted MCC: A Robust Measure of Multiclass Classifier Performance for Observations with Individual Weights Rommel Cortez, Bala Krishnamoorthy arXiv:2512.20811

Metadata

Release files for weighted-mcc 0.1.0

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

Source distribution (sdist)

Source distribution for weighted-mcc 0.1.0
File Size Uploaded Provenance
weighted_mcc-0.1.0.tar.gz 10.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for weighted-mcc 0.1.0
File Interpreter ABI Platform
weighted_mcc-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.2 kB

Release files / weighted_mcc-0.1.0.tar.gz

Download URL weighted_mcc-0.1.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ad0be16a0e18c5febf01b656027c0efefdfb7223099337e923488dd3bbf80be9
BLAKE2b-256 checksum
How to use checksums
feb48e833c017cbe05cb6ded846e9a7f6a9e90cec270290fa19ca705915a97cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Jan 28, 2026.

Transparency log

Release files / weighted_mcc-0.1.0-py3-none-any.whl

Download URL weighted_mcc-0.1.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40f8f448f4050943f04ec28f99cc511dadb75b32524a0cb3bd127c00dc71f939
BLAKE2b-256 checksum
How to use checksums
d33b195b326ebff2615025c874159055827e5b536614085a105dc556de551aed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Jan 28, 2026.

Transparency log

Security for weighted-mcc 0.1.0

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.

Select from 2 files

Attestation for weighted_mcc-0.1.0.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 Jan 28, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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