Introducing Scikit-P4: a simple library for Python

I’ve just released Scikit-P4, a small Python library that computes the P4 metric for binary, multiclass, and multilabel classification – using an API that mirrors scikit-learn’s metrics (think f1_score, but for P4).

Why P4?

Unlike the F1 metric, the P4 metric incorporates true negatives. Based on four conditional probabilities, it is more balanced than F1 and, in some cases, more desirable.

Highlights

  • Drop-in function: p4_score(y_true, y_pred)
  • Works across binary/multiclass/multilabel (auto-detected)
  • Micro / macro / weighted / samples averages for multi-case outputs
  • zero_division behavior aligned with scikit-learn

Install


pip install scikit-p4

Or add it to your Poetry project and poetry install.

Quick start


from skp4.metrics import p4_score

y_true = [0, 0, 0, 0, 1, 1, 1, 1, 0, 0]
y_pred = [0, 1, 0, 0, 1, 1, 1, 0, 1, 0]

print(p4_score(y_true, y_pred))

Links

Leave a Reply

Your email address will not be published. Required fields are marked *