{"uid":"cap_MefPqXakOsXpqj6qla2Il","slug":"machine-learning-metrics-confusion-matrix-92a22b10","name":"Machine Learning Metrics: Confusion Matrix","description":"Confusion matrix from true and predicted labels: accuracy, precision, recall, specificity, F1, MCC, kappa, averages.","url":"https://ml-metrics.x402tookit.com/confusion-matrix?utm_source=zero.xyz","method":"GET","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method"],"properties":{"type":{"type":"string","const":"http"},"method":{"enum":["GET"],"type":"string"},"queryParams":{"type":"object","required":["actual","predicted"],"properties":{"actual":{"type":"string","description":"True labels, comma-separated or JSON array, up to 10000 values"},"positive":{"type":"string","description":"For two classes: the label treated as positive (default: 1, true, or the last label in sorted order)"},"predicted":{"type":"string","description":"Predicted labels in the same order and length as actual"}}}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string"},"example":{"type":"object","properties":{"mcc":{"type":["null","number"]},"asOf":{"type":["null","string"]},"binary":{"type":["null","object"],"properties":{"f1":{"type":["null","number"]},"fn":{"type":["null","number"]},"fp":{"type":["null","number"]},"tn":{"type":["null","number"]},"tp":{"type":["null","number"]},"mcc":{"type":["null","number"]},"recall":{"type":["null","number"]},"accuracy":{"type":["null","number"]},"precision":{"type":["null","number"]},"cohenKappa":{"type":["null","number"]},"specificity":{"type":["null","number"]},"positiveLabel":{"type":["null","string"]},"balancedAccuracy":{"type":["null","number"]}}},"labels":{"type":["array","null"],"items":{"type":"string"}},"matrix":{"type":["array","null"],"items":{"type":"array","items":{"type":"number"}}},"source":{"type":["null","string"]},"reasons":{"type":["array","null"]},"summary":{"type":["null","string"]},"verdict":{"type":["null","string"]},"accuracy":{"type":["null","number"]},"averages":{"type":["null","object"],"properties":{"macro":{"type":["null","object"],"properties":{"f1":{"type":["null","number"]},"recall":{"type":["null","number"]},"precision":{"type":["null","number"]}}},"micro":{"type":["null","object"],"properties":{"f1":{"type":["null","number"]},"recall":{"type":["null","number"]},"precision":{"type":["null","number"]}}},"weighted":{"type":["null","object"],"properties":{"f1":{"type":["null","number"]},"recall":{"type":["null","number"]},"precision":{"type":["null","number"]}}}}},"degraded":{"type":["boolean","null"]},"perClass":{"type":["array","null"],"items":{"type":"object","properties":{"f1":{"type":["null","number"]},"fn":{"type":["null","number"]},"fp":{"type":["null","number"]},"tn":{"type":["null","number"]},"tp":{"type":["null","number"]},"label":{"type":["null","string"]},"recall":{"type":["null","number"]},"support":{"type":["null","number"]},"precision":{"type":["null","number"]},"specificity":{"type":["null","number"]}}}},"cohenKappa":{"type":["null","number"]},"disclaimer":{"type":["null","string"]},"matrixNote":{"type":["null","string"]},"notChecked":{"type":["array","null"],"items":{"type":"string"}},"sampleCount":{"type":["null","number"]},"undefinedRatioConvention":{"type":["null","string"]}}}}}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.02","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.02/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_cIgZX_PG00Nsth6ezKXgl","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.02","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Computes confusion matrix and derived classification metrics (accuracy, precision, recall, F1, MCC, Cohen's kappa, etc.) from true and predicted labels","exampleAgentPrompt":"Can you compute the confusion matrix and full classification metrics — accuracy, precision, recall, F1, MCC, and Cohen's kappa — for these predictions? Actual labels: 0,1,1,0,1,0,0,1 and predicted: 0,1,0,0,1,1,0,1, treating 1 as the positive class.","exampleUseCases":[{"title":"Binary classifier evaluation after training","prompt":"I just finished training a spam detector — here are the actual labels and model predictions for my test set (both comma-separated, 500 values each). Can you compute the full confusion matrix and metrics like F1, precision, recall, and MCC, treating 'spam' as the positive class?"},{"title":"Multiclass model performance report","prompt":"I have actual and predicted class labels for a 5-class image classifier across 2000 test samples. Can you give me the confusion matrix plus macro and weighted averages for precision, recall, and F1?"},{"title":"Comparing two models head-to-head","prompt":"I want to compare two models on the same test set — can you compute confusion matrix metrics for each? First run: actual labels are 0,1,0,1,1,0 and model A predicted 0,1,1,1,0,0. Second run use the same actuals but model B predicted 1,1,0,1,1,0. Use 1 as the positive class for both."}],"resultDescription":"Returns a confusion matrix (2D array of counts), per-class and aggregate classification metrics including accuracy, precision, recall, specificity, F1, MCC, Cohen's kappa, and balanced accuracy. For binary problems, also returns TP, FP, TN, FN counts and the positive label used. Includes macro, micro, and weighted averages for multiclass scenarios.","failureModes":["Mismatched lengths between actual and predicted arrays causes an error","Invalid or non-JSON-parseable label strings rejected","Empty label arrays return null or error","Ambiguous positive class with more than 2 labels if not specified explicitly","Very large arrays (>10000 values) may be rejected or truncated","Non-string or mixed-type labels may cause parsing issues"],"whenToPreferThis":"Use this endpoint when you need a comprehensive set of classification metrics computed from raw true and predicted labels in a single call, especially when you need both binary-specific metrics (TP/FP/TN/FN, specificity, MCC) and multiclass averages (macro/micro/weighted) together. Prefer this over custom code when you want a fast, reliable, pay-per-use computation without spinning up a Python environment. Best suited for post-training evaluation pipelines or reporting tasks.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-11-02T12:31:09.348Z","isFirstParty":false,"canonicalSlug":"machine-learning-metrics-confusion-matrix-92a22b10"}