Skip to content

Add the baseline corrected accuracy score for (multi-class) classification to sklearn.metrics #31244

Closed as not planned
@Carl-McBride-Ellis

Description

@Carl-McBride-Ellis

Describe the workflow you want to enable

Would it be possible to add a new score to sklearn.metrics, namely the baseline corrected accuracy score (BCAS) (DOI:10.5281/zenodo.15262049). The proposed metric quantifies the model improvement w.r.t. the baseline, and represents a direct evaluation of classifier performance. See the proposed code below, which is label agnostic, and is suitable for both binary and multi-class classification.

Describe your proposed solution

import numpy as np

def BCAS(y_true, y_pred):
    """Baseline corrected accuracy score (BCAS).

    Parameters
    ----------
    y_true : Ground truth (correct) labels.

    y_pred : Predicted labels.

    Returns
    -------
    score : float
    """
    label, count = np.unique(y_true, return_counts=True)
    most_frequent_class = label[np.argmax(count)]
    y_baseline = np.full(len(y_true), most_frequent_class)
    as_baseline = np.mean(y_true == y_baseline)
    as_predicted = np.mean(y_true == y_pred)
    return (as_predicted - as_baseline)

Describe alternatives you've considered, if relevant

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions