# Accuracy, F1, balanced accuracy and Matthews correlation coefficient of a binary classification, version 1.0.1

score-binary-classification\@1.0.1: this version's equations with their symbols, each constant's value, their sources and whether each was read, a worked example where the record holds one, its level and what it was checked against, the number of cases, and what was not checked. This version's record is not rewritten; a correction is added under Changes.

## What this page can and cannot show

**Level: Checked against a reference; Undefined scores withheld; Chicco and Jurman's fill-in values not applied. Reference kind: our own exact-arithmetic script and a hand-worked case; the source's own worked example, Chicco and Jurman 2020, Table 4 (printed values), version of record.**

Checked by this project, not independently reviewed. Every method on this page has its equations, constants, sources and cases on record, and its cases agree with the stated reference within the stated tolerance. A reader can follow each method's worked example by hand; that shows the stated method gives the stated answer for one set of inputs, and does not test the code. The other cases and their values are not printed, so a reader cannot re-run these checks. No independent scientist has yet reviewed them.

[Every version of this method](https://www.drybench.com/methods/m/score-binary-classification) · [Every method](https://www.drybench.com/methods/m) · [What the levels mean](https://www.drybench.com/methods/levels)

## Version 1.0.1

**Level: Checked against a reference; Undefined scores withheld; Chicco and Jurman's fill-in values not applied. Reference kind: our own exact-arithmetic script and a hand-worked case; the source's own worked example, Chicco and Jurman 2020, Table 4 (printed values), version of record.** `score-binary-classification@1.0.1`

Built, not hosted. Generated from a snapshot of the library's records taken on 2026-11-25, as committed on 2026-11-25. A later snapshot replaces this one, so these records and this page can change.

**Verification statement:** Accuracy, F1, balanced accuracy and MCC as in Chicco and Jurman 2020 (Eqs. 1, 2 and 4) and Chicco, Tötsch and Jurman 2021 (Eq. 6), re-read at source 14 November 2026 with matching SHA-256; Table 4 reproduced. Compared with scikit-learn 1.9.1, the source's six printed cases, and a second implementation in Python by a separate agent of the same model family (55 cases, 19 at the edges). The source's Figure 1 caption and Table 4 print use case A1's coefficient differently in the second decimal; the table agrees with the equation. Matthews 1975 not read.

From the four counts of a 2 × 2 confusion matrix: accuracy (TP + TN)/N; F1 = 2TP/(2TP + FP + FN), which is also the Dice coefficient of the predicted and the actual positive sets; balanced accuracy, the mean of the true positive rate and the true negative rate; and the Matthews correlation coefficient. A score whose formula gives zero over zero on the counts is withheld, not filled in; with all four counts zero the call is refused. The numerator and the product under the root of the coefficient are formed exactly, in integers.

- **How results are reported:** none: full double precision
- **Uncertainty:** Arithmetic on the caller's counts; no sampling interval is computed for any score.
- **Reference, as its record states it:** Exact arithmetic (Python fractions; one square root at 60 digits), checked against scikit-learn 1.9.1 and the primary source's six printed cases
- **Level confirmed by this project's ruling of** 14 November 2026

[What this page can and cannot show](#what-this-page-can-and-cannot-show)

### What was checked

91 cases in 3 files, linked by this exact version.

Run through the tool at build against our own exact-arithmetic script and a hand-worked case; the source's own worked example, Chicco and Jurman 2020, Table 4 (printed values), version of record: 82 agree within the tolerance the file states, 9 refuse as the case expects, 0 differ, 0 were not run.

- **File 1, 29 cases**
  - **Where the expected values came from:** our own exact-arithmetic script and a hand-worked case
  - **Recorded on:** 2026-11-12
  - **Reference:** Python standard library (fractions, decimal), 3.13.18; licence PSF-2.0
  - **Tolerance as the file states it:** accuracy, F1, balanced accuracy and MCC relative 1e-12, with a floor of 1e-18 below 1e-6; statuses, codes, withholding rules and units exact

- **File 2, 7 cases**
  - **Where the expected values came from:** the source's own worked example, Chicco and Jurman, BMC Genomics 21:6 (2020), doi 10.1186/s12864-019-6413-7, Table 4: six confusion matrices with their accuracy, F1 score and MCC
  - **Recorded on:** 2026-11-12
  - **Reference:** Chicco and Jurman 2020, Table 4 (printed values), version of record; licence CC-BY-4.0
  - **Tolerance as the file states it:** accuracy, F1 and MCC absolute 0.005 (half a unit in the printed second decimal); balanced accuracy relative 1e-12 against scikit-learn; statuses, codes and units exact

- **File 3, 55 cases**
  - **Where the expected values came from:** our own exact-arithmetic script and a hand-worked case
  - **Recorded on:** 2026-11-14
  - **Reference:** second implementation by a fresh agent (Python 3.13), 2026-11-14; licence BSD-3-Clause
  - **Tolerance as the file states it:** every number relative 1e-15 (absolute 1e-30 below 1e-15, in each value's unit); counts, statuses, codes, labels and strings exact

Apart from the worked example, the cases and their values are not printed here. This shows agreement with this project's recorded cases. It does not show that a method suits your work, and it is not a qualification.

### What was not checked

The predictions, the decision threshold and the test set behind the counts; scores for more than two classes; the fill-in values the first source proposes for undefined scores, which this method does not adopt; Matthews (1975), the coefficient's primary source, unread; any sampling interval.

### Definition or model

A closed form: the result follows from the inputs by the equations alone.

### Equations

**Equation 1**

```equation
N = TP + FP + FN + TN
accuracy = (TP + TN)/N
```

| Symbol | Meaning and unit |
| --- | --- |
| TP | true positives: actual positives predicted positive (argument truePositive) |
| FP | false positives: actual negatives predicted positive (argument falsePositive) |
| FN | false negatives: actual positives predicted negative (argument falseNegative) |
| TN | true negatives: actual negatives predicted negative (argument trueNegative) |
| N | the number of observations scored |
| accuracy | the fraction of observations predicted correctly, returned as accuracy |

Source: Chicco D, Jurman G, The advantages of the Matthews correlation coefficient (MCC) over F1 score and accuracy in binary classification evaluation, BMC Genomics 21:6 (2020), equation 1, section Notation and mathematical foundations, version of record (BMC) as deposited in PMC; Europe PMC's JATS XML, not the publisher's copy; read in full on 2026-11-12 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning 8c497f0d0c93. Free to read (CC BY 4.0), checked 2026-11-12. No erratum found (searched crossref, europe-pmc, retraction-watch), 2026-11-12.

**Equation 2**

```equation
F1 = 2·TP/(2·TP + FP + FN)
```

| Symbol | Meaning and unit |
| --- | --- |
| TP | true positives: actual positives predicted positive (argument truePositive) |
| FP | false positives: actual negatives predicted positive (argument falsePositive) |
| FN | false negatives: actual positives predicted negative (argument falseNegative) |
| F1 | the harmonic mean of precision and recall in its count form, returned as f1Score; undefined when TP + FP + FN = 0 |

Source: Chicco D, Jurman G, The advantages of the Matthews correlation coefficient (MCC) over F1 score and accuracy in binary classification evaluation, BMC Genomics 21:6 (2020), equation 4, section Notation and mathematical foundations, version of record (BMC) as deposited in PMC; Europe PMC's JATS XML, not the publisher's copy; read in full on 2026-11-12 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning 8c497f0d0c93. Free to read (CC BY 4.0), checked 2026-11-12. No erratum found (searched crossref, europe-pmc, retraction-watch), 2026-11-12.

**Equation 3**

```equation
TPR = TP/(TP + FN)
TNR = TN/(TN + FP)
balanced accuracy = (TPR + TNR)/2
```

| Symbol | Meaning and unit |
| --- | --- |
| TP | true positives: actual positives predicted positive (argument truePositive) |
| FP | false positives: actual negatives predicted positive (argument falsePositive) |
| FN | false negatives: actual positives predicted negative (argument falseNegative) |
| TN | true negatives: actual negatives predicted negative (argument trueNegative) |
| TPR | true positive rate (sensitivity, recall); undefined when there is no actual positive |
| TNR | true negative rate (specificity); undefined when there is no actual negative |
| balanced accuracy | the mean of the two rates, returned as balancedAccuracy |

Source: Chicco D, Tötsch N, Jurman G, The Matthews correlation coefficient (MCC) is more reliable than balanced accuracy, bookmaker informedness, and markedness in two-class confusion matrix evaluation, BioData Mining 14:13 (2021), equation 6, section Introduction, version of record (BMC) as deposited in PMC; Europe PMC's JATS XML, not the publisher's copy; read in full on 2026-11-12 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning 2a3f1c585c89. Free to read (CC BY 4.0), checked 2026-11-12. No erratum found (searched crossref, europe-pmc, retraction-watch), 2026-11-12.

**Equation 4**

```equation
MCC = (TP·TN − FP·FN)/√((TP + FP)·(TP + FN)·(TN + FP)·(TN + FN))
```

| Symbol | Meaning and unit |
| --- | --- |
| TP | true positives: actual positives predicted positive (argument truePositive) |
| FP | false positives: actual negatives predicted positive (argument falsePositive) |
| FN | false negatives: actual positives predicted negative (argument falseNegative) |
| TN | true negatives: actual negatives predicted negative (argument trueNegative) |
| MCC | Matthews correlation coefficient, from −1 to 1, returned as matthewsCorrelation; undefined when any of the four sums under the root is zero |

Source: Chicco D, Jurman G, The advantages of the Matthews correlation coefficient (MCC) over F1 score and accuracy in binary classification evaluation, BMC Genomics 21:6 (2020), equation 2, section Notation and mathematical foundations, version of record (BMC) as deposited in PMC; Europe PMC's JATS XML, not the publisher's copy; read in full on 2026-11-12 by an AI-assisted session; not yet checked by a person. Read from the file itself, SHA-256 beginning 8c497f0d0c93. Free to read (CC BY 4.0), checked 2026-11-12. No erratum found (searched crossref, europe-pmc, retraction-watch), 2026-11-12.

### Constants

Constants: none used.

### Worked example

Worked example: one case of score-binary-classification\@1.0.1, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

**Inputs**

- truePositive = 6
- falsePositive = 2
- falseNegative = 3
- trueNegative = 9

**Steps**

1. total = 20, from truePositive, falsePositive, falseNegative, trueNegative; by equation 1.
2. accuracy = 0.75, from truePositive, trueNegative, total; by equation 1; gives accuracy.
3. f1 = 0.70588235, from truePositive, falsePositive, falseNegative; by equation 2; gives f1Score.
4. truePositiveRate = 0.66666667, from truePositive, falseNegative; by equation 3.
5. trueNegativeRate = 0.81818182, from trueNegative, falsePositive; by equation 3.
6. balancedAccuracy = 0.74242424, from truePositiveRate, trueNegativeRate; by equation 3; gives balancedAccuracy.
7. numerator = 48, from truePositive, falsePositive, falseNegative, trueNegative; by equation 4.
8. marginalProduct = 9504, from truePositive, falsePositive, falseNegative, trueNegative; by equation 4.
9. root = 97.488461, from marginalProduct; by equation 4.
10. mcc = 0.49236596, from numerator, root; by equation 4; gives matthewsCorrelation.

The working, as the case writes it:

```equation
N = 20
accuracy = 15/20 = 0.75
F1 = 12/(12 + 2 + 3) = 12/17 = 0.70588235
TPR = 6/9 = 0.66666667, TNR = 9/11 = 0.81818182, balanced accuracy = 0.74242424
MCC = (6·9 − 2·3)/√(8·9·11·12) = 48/√9504 = 48/97.488461 = 0.49236596 (worked by hand by Drybench on 12 November 2026
not an independent check)
```

**Answer**

- `accuracy` = **0.75**
- `f1Score` = **0.70588235**
- `balancedAccuracy` = **0.74242424**
- `matthewsCorrelation` = **0.49236596**

Where these values came from: our own exact-arithmetic script and a hand-worked case; stored reference values (fractions; 60-digit decimal square root).

At build the tool returned this answer within the tolerance the file states: accuracy, F1, balanced accuracy and MCC relative 1e-12, with a floor of 1e-18 below 1e-6; statuses, codes, withholding rules and units exact.

Who worked this case: not recorded.

### What it refuses, and its input ranges

- `NO_OBSERVATIONS`: all four counts are zero: there is nothing to score Next: Give the four counts of the confusion matrix; where every count is truly zero, no change of input makes this computable on these data.
- `COUNTS_ABOVE_RANGE`: a count is above the method's range, beyond which the sums of the counts are no longer held exactly Next: Check the counts; where they are as intended, no change of input makes this computable by this method.

**Input ranges:** truePositive: at most 1000000000000000; outside it, refused (COUNTS\_ABOVE\_RANGE). falsePositive: at most 1000000000000000; outside it, refused (COUNTS\_ABOVE\_RANGE). falseNegative: at most 1000000000000000; outside it, refused (COUNTS\_ABOVE\_RANGE). trueNegative: at most 1000000000000000; outside it, refused (COUNTS\_ABOVE\_RANGE).

### Changes

No correction is logged for score-binary-classification\@1.0.1.

## Tools that use it

- [`score_binary_classification`](https://www.drybench.com/methods/tools/score-binary-classification)

## Cite this version

Accuracy, F1, balanced accuracy and Matthews correlation coefficient of a binary classification. Drybench; score-binary-classification\@1.0.1; [https://www.drybench.com/methods/m/score-binary-classification/1.0.1](https://www.drybench.com/methods/m/score-binary-classification/1.0.1) (accessed \[date\]).
