# Machine Learning Metrics: Confusion Matrix

> Machine Learning Metrics: Confusion Matrix is a paid API for AI agents from ml-metrics.x402tookit.com, paid per call via x402, $0.02/call, status unknown (last checked 2026-11-02).

Computes confusion matrix and derived classification metrics (accuracy, precision, recall, F1, MCC, Cohen's kappa, etc.) from true and predicted labels

## Facts

- Endpoint: GET https://ml-metrics.x402tookit.com/confusion-matrix?utm_source=zero.xyz
- Price: $0.02/call
- Payment: x402
- Status: unknown
- Last checked: 2026-11-02
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/machine-learning-metrics-confusion-matrix-92a22b10
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_MefPqXakOsXpqj6qla2Il

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability machine-learning-metrics-confusion-matrix-92a22b10
```

Example prompt: 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.

## When to prefer this

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.

## Known failure modes

- 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

## How this service works

Confusion matrix from true and predicted labels: accuracy, precision, recall, specificity, F1, MCC, kappa, averages.

## Output

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.

## Request schema (JSON Schema)

```json
{
 "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",
    
… (truncated)
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/machine-learning-metrics-confusion-matrix-92a22b10/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from ml-metrics.x402tookit.com](https://www.zero.xyz/host/ml-metrics.x402tookit.com/llms.txt)
