# Classification metrics compute

`classification-metrics-compute` · version 1.0.0 · Numbers & math · free, no key needed

Compute exact binary-classification metrics from integer confusion-matrix counts as reduced fractions or null.

**Use when you need to: compute binary classification metrics · confusion matrix precision recall and f1 · exact accuracy from tp fp tn fn.**

## Decide before calling

Read the [versioned contract](/v1/tools/classification-metrics-compute/versions/1.0.0) and the supported scope below. Reuse `classification-metrics-compute@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `classification-metrics-compute@1.0.0` for compute binary classification metrics. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- compute binary classification metrics
- confusion matrix precision recall and f1
- exact accuracy from tp fp tn fn
- calculate sensitivity and specificity
- negative predictive value from counts
- balanced accuracy as a fraction
- classification prevalence from confusion matrix

## Not supported

- multiclass confusion matrices
- confidence intervals or hypothesis tests
- threshold selection or ROC curves

## Behavior

- Counts tp, fp, tn and fn are required non-negative integers at most 1000000000.
- Metrics use standard confusion-matrix definitions and return reduced n/d strings; an exactly zero numerator is 0/1.
- A metric with a zero denominator is null; the all-zero matrix is valid and makes every metric null.
- balanced_accuracy is the exact arithmetic mean of recall and specificity and is null if either component is undefined.
- No decimal approximation or rounding occurs; output field order is fixed and input is not mutated.

## Input

- `tp` (integer, required): min 0; max 1000000000
- `fp` (integer, required): min 0; max 1000000000
- `tn` (integer, required): min 0; max 1000000000
- `fn` (integer, required): min 0; max 1000000000

## Output

- `total` (integer, required): min 0; max 4000000000
- `accuracy` (string or null, required)
- `precision` (string or null, required)
- `recall` (string or null, required)
- `specificity` (string or null, required)
- `f1` (string or null, required)
- `negative_predictive_value` (string or null, required)
- `prevalence` (string or null, required)
- `balanced_accuracy` (string or null, required)

## Limits

- max count: 1000000000
- max input bytes: 256

## Example

Request input:

```json
{
  "tp": 42,
  "fp": 8,
  "tn": 45,
  "fn": 5
}
```

Response:

```json
{
  "result": {
    "total": 100,
    "accuracy": "87/100",
    "precision": "21/25",
    "recall": "42/47",
    "specificity": "45/53",
    "f1": "84/97",
    "negative_predictive_value": "9/10",
    "prevalence": "47/100",
    "balanced_accuracy": "4341/4982"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "classification-metrics-compute",
  "version": "1.0.0",
  "input": {
    "tp": 42,
    "fp": 8,
    "tn": 45,
    "fn": 5
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/classification-metrics-compute/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"tp":42,"fp":8,"tn":45,"fn":5}'
```

The machine-readable contract is at [/v1/tools/classification-metrics-compute/versions/1.0.0](/v1/tools/classification-metrics-compute/versions/1.0.0).

### CLI

```sh
node cli.mjs run classification-metrics-compute 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Number engineering format](/tools/number-engineering-format): Format an exact decimal in scientific or engineering notation with explicit precision and rounding.
- [Rational power](/tools/rational-power): Raise a rational number to an integer exponent and return the exact reduced result.
- [Rational reciprocal](/tools/rational-reciprocal): Invert a rational number given as a numerator/denominator integer-string pair.
- [Roman numeral convert](/tools/roman-numeral-convert): Convert integers 1–3999 to canonical Roman numerals and strictly parse canonical numerals back to integers.
- [Array integer clamp](/tools/array-integer-clamp): Clamp an array of canonical integer strings to optional inclusive min and max bounds.
- [Array integer GCD](/tools/array-integer-gcd): Compute the non-negative greatest common divisor of an array of canonical integer strings.
