Compute the balanced_accuracy_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute balanced_accuracy_score, or asks how to score with balanced_accuracy_score.
Scanned 9/11/2026
Install to Claude Code
npx -y skills add qhjqhj00/research-skills-pool --skill balanced-accuracy-score --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Balanced Accuracy Score?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-balanced-accuracy-score)More formats (shields.io, HTML) on the badges page.
---
name: balanced-accuracy-score
description: Compute the balanced_accuracy_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute balanced_accuracy_score, or asks how to score with balanced_accuracy_score.
metadata:
skill_kind: metric
source_lib: scikit-learn
import_path: sklearn.metrics.balanced_accuracy_score
source: library_introspection
---
# balanced-accuracy-score
> Metric `balanced_accuracy_score` from `scikit-learn` (sklearn.metrics.balanced_accuracy_score)
## When to invoke this skill
The user has predictions + ground truth and asks to evaluate with balanced_accuracy_score, or
mentions `sklearn.metrics.balanced_accuracy_score` directly, or wants the standard scikit-learn implementation.
## Reference signature
```python
from sklearn.metrics import balanced_accuracy_score
# balanced_accuracy_score(y_true, y_pred, *, sample_weight=None, adjusted=False)
```
## Library docstring
```
Compute the balanced accuracy.
The balanced accuracy in binary and multiclass classification problems to
deal with imbalanced datasets. It is defined as the average of recall
obtained on each class.
The best value is 1 and the worst value is 0 when ``adjusted=False``.
Read more in the :ref:`User Guide <balanced_accuracy_score>`.
.. versionadded:: 0.20
Parameters
----------
y_true : array-like of shape (n_samples,)
Ground truth (correct) target values.
y_pred : array-like of shape (n_samples,)
Estimated targets as returned by a classifier.
sample_weight : array-like of shape (n_samples,), default=None
Sample weights.
adjusted : bool, default=False
When true, the result is adjusted for chance, so that random
performance would score 0, while keeping perfect performance at a score
of 1.
Returns
-------
balanced_accuracy : float
Balanced accuracy score.
See Also
--------
average_precision_score : Compute average precision (AP) from prediction
scores.
precision_score : Compute the precision score.
recall_score : Compute the recall score.
roc_auc_score : Compute Area Under the Receiver Operating Characteristic
Curve (ROC AUC) from prediction scores.
Notes
-----
Some literature promotes alternative definitions of balanced accuracy. Our
definition is equivalent to :func:`accuracy_score` with class-balanced
sample weights, and shares desirable properties with the binary case.
See the :ref:`User Guide <balanced_accuracy_score>`.
References
----------
.. [1] Brodersen, K.H.; Ong, C.S.; Stephan, K.E.; Buhmann, J.M. (2010).
The balanced accuracy and its posterior distribution.
Proceedings of the 20th International Conference on Pattern
Recognition, 3121-24.
.. [2] John. D. Kelleher, Brian Mac Namee, Aoife D'Arcy, (2015).
`Fundamentals of Machine Learning for Predictive Data Analytics:
Algorithms, Worked Examples, and Case Studies
<https://mitpress.mit.edu/books/fundamentals-machine-learning-predictive-data-analytics>`_.
Examples
--------
>>> from sklearn.metrics import balanced_accuracy_score
>>> y_true = [0, 1, 0, 0, 1, 0]
>>> y_pred = [0, 1, 0, 0, 0, 1]
>>> balanced_accuracy_score(y_t
```
## Quick recipe
```python
import sklearn.metrics as _m
score = _m.balanced_accuracy_score(y_true, y_pred)
```
## Don'ts
- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is `(y_true, y_pred)` while torchmetrics is `(preds, target)`.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!