Matthews correlation (MCC)
With 50 true positives, 40 true negatives, 5 false positives and 5 false negatives, the Matthews correlation coefficient is 0.79798. Enter the four counts of your confusion matrix and get one balanced score for a yes-or-no classifier. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Tp
- 50
- Tn
- 40
- Fp
- 5
- Fn
- 5
- Decimal places
- 6
- Mcc
- 0.79798
MCC from TP/TN/FP/FN confusion counts. Search intent: matthews correlation coefficient calculator. No network calls or random seeds are required. Failed jobs are not billed.
Four counts, one score
A binary classifier sorts each case into yes or no, and comparing its calls with the truth gives four counts. True positives are the yes cases it caught, true negatives the no cases it cleared, false positives the no cases it wrongly flagged and false negatives the yes cases it missed. The Matthews correlation coefficient folds all four into one number. Multiply the true positives by the true negatives, subtract the false positives times the false negatives, and divide by the square root of the product of the four sums. With 50, 40, 5 and 5 the score is 0.79798.
Reading the result and rounding it
Because the formula uses every cell of the confusion matrix, both kinds of mistake, false positives and false negatives, weigh on the result. The coefficient behaves like a correlation between predictions and reality and runs from −1 to 1: the closer to 1, the better they agree. If you ask for a number of decimals, the raw value is rounded half-up once, at the end, so no error builds up. The four counts are shown next to the score, which makes it easy to confirm that the right figures went in.
What you can do with it
Teaching
Pinned goldens.
FAQ
What do I need to calculate the Matthews correlation coefficient?
Only the four counts of a confusion matrix: true positives, true negatives, false positives and false negatives. You do not need the individual predictions, just how many cases fell into each cell.
What is the formula for MCC?
Multiply TP by TN, subtract FP times FN, then divide by the square root of (TP+FP)(TP+FN)(TN+FP)(TN+FN). The calculator applies that formula directly to the counts you enter.
How is MCC different from an ordinary correlation coefficient?
An ordinary correlation compares two lists of paired measurements. MCC starts instead from the four counts of a yes-or-no classification, so it measures how well the predicted labels agree with the true ones.
Does the calculator round the result?
Only when you choose a number of decimals. The unrounded result is then rounded half-up exactly once, at the end, so small rounding errors never pile up between steps.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/stat/matthews-corr \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"tp":50,"tn":40,"fp":5,"fn":5}'const res = await fetch("https://api.kit.forhosting.com/stat/matthews-corr", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"tp": 50,
"tn": 40,
"fp": 5,
"fn": 5
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/stat/matthews-corr",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"tp": 50,
"tn": 40,
"fp": 5,
"fn": 5
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/stat/matthews-corr", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"tp":50,"tn":40,"fp":5,"fn":5}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"tp":50,"tn":40,"fp":5,"fn":5}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/stat/matthews-corr", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"tp": 50,
"tn": 40,
"fp": 5,
"fn": 5
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "stat.matthews_corr",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos.
How it works
MCC from TP/TN/FP/FN confusion counts. MCC=(TP·TN−FP·FN)/√((TP+FP)(TP+FN)(TN+FP)(TN+FN)). No network calls or random seeds are required. Failed jobs are not billed. No network calls or random seeds are required. Failed jobs are not billed. The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos. The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos.
Inputs, limits and rounding
Optional decimals use half-up once. Outputs echo inputs. No network calls or random seeds are required. Failed jobs are not billed. No network calls or random seeds are required. Failed jobs are not billed. Provide required JSON fields. Invalid types raise invalid_input. The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos. The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos.
When to use it
Use when search intent matches. MCC from TP/TN/FP/FN confusion counts. No network calls or random seeds are required. Failed jobs are not billed. No network calls or random seeds are required. Failed jobs are not billed. The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos. The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos.
Integration use cases
Quick check
Free widget.
Automation
Same JSON via API.
Technical questions
Free?
Yes tier A.
Network?
No.
Bad input?
invalid_input.
API?
Yes.
Locales?
EN-only; Nitro hydrates.