JSON Formatter and Validator
Format, minify, validate, and sort JSON in your browser, with error messages that point to the exact line and column of a syntax problem.
Open tool
Machine learning tool
Calculate accuracy, precision, recall, F1, specificity, balanced accuracy, and Matthews correlation coefficient from a binary confusion matrix.
Enter non-negative whole numbers.
Actual positive, predicted positive
Actual positive, predicted negative
Actual negative, predicted positive
Actual negative, predicted negative
“undefined” means the metric’s denominator is zero for these counts (for example, precision when there are no positive predictions).
Enter the four counts from a binary classifier’s confusion matrix. All metrics update immediately. A metric shows as “undefined” when its denominator is zero; for example, precision is undefined when the model made no positive predictions.
A binary classifier’s predictions fall into four groups:
| Actual \ predicted | Predicted positive | Predicted negative |
|---|---|---|
| Actual positive | True positive (TP) | False negative (FN) |
| Actual negative | False positive (FP) | True negative (TN) |
Every metric in this calculator is a different summary of these four numbers.
Accuracy is the share of all predictions that were correct. It is easy to explain but misleading on imbalanced data: if 1% of transactions are fraudulent, a model that never predicts fraud is 99% accurate and completely useless.
Precision answers “when the model says positive, how often is it right?” Optimise for precision when false positives are expensive, such as flagging legitimate emails as spam.
Recall (sensitivity, true positive rate) answers “of all actual positives, how many did the model find?” Optimise for recall when missing a positive is costly, such as screening for a disease.
F1 score is the harmonic mean of precision and recall:
The harmonic mean is pulled toward the smaller value, so F1 is only high when both precision and recall are high. Note that F1 ignores true negatives entirely.
Specificity (true negative rate) is recall for the negative class: the share of actual negatives correctly identified.
Balanced accuracy averages recall and specificity, giving each class equal weight regardless of how many samples it has.
Matthews correlation coefficient (MCC) uses all four cells:
It ranges from −1 (complete disagreement) through 0 (no better than chance) to 1 (perfect prediction). Because it accounts for every type of error, MCC is a strong single-number summary for imbalanced problems.
The same metrics are available in scikit-learn, which is a useful cross-check:
from sklearn.metrics import f1_score, matthews_corrcoef, precision_score, recall_score
y_true = [1, 1, 0, 0, 1, 0]
y_pred = [1, 0, 0, 1, 1, 0]
print(precision_score(y_true, y_pred)) # 0.667
print(recall_score(y_true, y_pred)) # 0.667
print(f1_score(y_true, y_pred)) # 0.667
print(matthews_corrcoef(y_true, y_pred)) # 0.333
Format, minify, validate, and sort JSON in your browser, with error messages that point to the exact line and column of a syntax problem.
Open tool
Encode text to Base64 or decode Base64 back to text, with full UTF-8 support and an optional URL-safe alphabet for tokens and URLs.
Open tool
Convert Unix timestamps in seconds or milliseconds to readable UTC and local dates, and convert dates back to timestamps, with live current time.
Open tool