# ModelCompareApp

Source: https://obsvra.com/docs/modelcompareapp

> The compare command: generate as many rows as a real data sample has, compare the two column by column, and report each difference by severity.

> © 2026 Obsvra. This document describes SpiceGrinder and is provided to help you evaluate and use it. It is not a license to reproduce, adapt, or use this material to build a competing product or service. Full terms: the SpiceGrinder EULA.

## NAME

ModelCompareApp — compare a model's generated output with a real data sample

## SYNOPSIS

```
java -cp spicegrinder.jar com.obsvra.spicegrinder.tools.ModelCompareApp [options] model sample.csv
```

On a jpackage install:

```
compare [options] model sample.csv
```

In Windows PowerShell, `compare` alone is PowerShell's own alias for Compare-Object (it answers, for example, that it has no `--html` parameter). Use `compare-model`, which the desktop app's full install adds as another name for this tool, `compare.exe`, or the full path.

## DESCRIPTION

`compare` answers "how close is what this model generates to the real data it's meant to resemble?" It generates as many rows as the sample has (or `--count`), in-process, printing each value exactly as `grind` would, then compares the two tables column by column and reports where they differ, each difference with a severity. Use it after fitting a model to data, by hand or with the fit-model-to-sample agent skill: the skill's own notes say what it believes it did, and `compare` measures it.

The model must produce one value per sample column, in the sample's column order. The sample is a delimited text file, by default comma-separated with a header row; double-quoted cells may contain the delimiter. Run `compare` from the directory the model's relative data file paths are relative to, as with `grind`.

The same check is available to AI agents as the MCP server's `compare_to_sample` tool, which takes the model as text and the sample as text or a path (see [McpServerApp.md](https://obsvra.com/docs/mcpserverapp#compare_to_sample)).

Each column is one of three kinds, decided from the sample:

- **code**: every value a digit string of the same length (3 or more), with more than 50 distinct values. ZIP codes, NPIs, account numbers: labels, not quantities, so only format and copying are checked.
- **numeric**: at least 95% of non-empty values are plain decimal numbers.
- **text**: everything else.

Checks, with the thresholds that set each severity:

| Check | Applies to | Medium | High |
|---|---|---|---|
| Whole numbers printed with a decimal point (sample `12`, output `12.0`) | all | | any |
| Leading zeros lost (sample `02134`, output never starts with 0) | all | | sample has 1%+ with a leading zero |
| Decimal places (most common count differs; low when the gap is smaller) | numeric, text | output has 3+ more places | |
| Character pattern of values (`99999` vs `99999.9`, `9 Aa Aa` vs `Aa Aa`) | code, text | over 50% of values differ | |
| Distribution (Kolmogorov-Smirnov distance) | numeric | over 0.1 | over 0.2 |
| Tail percentiles p1, p5, p95, p99, judged against their bootstrapped sampling noise | numeric | over 3 standard errors apart | over 5 |
| Values outside the sample's range | numeric | over 1% | |
| Frequent exact values (1% of the sample or more) that lost or gained share (under half or over double, and 1 point or more off) | numeric | values under 5% of the sample, summarized per column | a value holding 5% or more |
| Category frequencies (total variation distance), for 50 or fewer distinct sample values | text | over 0.1 | over 0.2 |
| Values never seen in a small category set | text | over 5% | |
| Values repeating across rows: distinct values over the same number of rows (for 50 or more distinct sample values), catching a model that makes a new entity on every row where the sample repeats providers, customers or vehicles | code, text | over 1.5 times or under 2/3 of the sample's | over 2 times or under half |
| Identifier values copied verbatim from the sample | code, text with digits, 90%+ distinct | | over 1%, and for codes over 5 times what random draws would overlap |
| Rank correlation (Spearman) between numeric columns | numeric pairs | gap over 0.1 | gap over 0.2 |

The remedy for a "new entity on every row" finding is a `Pool` (see [Component-Library-Reference.md](https://obsvra.com/docs/component-library-reference#pool--free)).

Tail percentiles are compared against their own noise because a heavy-tailed column's p99 varies a lot between two samples of the same data: at 5,000 rows, two halves of a real Medicare extract disagreed on p99 by a third. Without that allowance the check would flag real data as wrong.

What it doesn't check: relationships among more than two columns, text columns' dependence on numeric ones, anything row by row. No findings means these checks found nothing, not that the model is right: see [Reviewing-a-Fitted-Model.md](https://obsvra.com/docs/reviewing-a-fitted-model) for what to check by hand after `compare`. Replaying the real sample itself through `compare` (in Pro, a `FlatFile` over one half of the data, compared with the other half) is a good way to see the noise floor for a given dataset.

Available at any tier.

## OPTIONS

```
--count N        generate N rows instead of as many as the sample has
--seed N         seed for the generated rows (default: the model's own embedded seed, else a random one;
                 the seed used is always printed, so a run can be repeated)
--no-header      the sample's first row is data, not column names (columns are then called column 1, 2, ...). Comment lines starting with `# ` above the first row, such as the `# seed=42 -- reproduce with: ...` line at the top of `samples/dnd-ability-scores.csv`, are skipped either way.
--delimiter C    sample field separator (default ,; "tab" for tab)
--json           one JSON report on stdout instead of text
--score          add the classifier score (see below); in JSON, a "classifier" object
--html FILE      also write the comparison as one HTML page with charts (implies --score; see below)
--local-root DIR the model's local root for this run (ahead of project.root, .spicegrinder-root and the
                 Git top): data files and Imports not beside the model are looked for there
--model-dir DIR  with - (stdin): resolve relative paths as if the model were saved in DIR
--show-sample-values
                 show the sample's real values in examples for codes, names, addresses and other
                 many-valued text (default: only their character pattern, such as 999 Aa Aa)
-h, --help       usage
--version        print version and exit
```

## OUTPUT (JSON)

The shape, with illustrative values:

```json
{
  "model": "model.xml",
  "sample": "sample.csv",
  "seed": 42,
  "sampleRows": 5000,
  "outputRows": 5000,
  "highSeverity": true,
  "findings": [
    {"severity": "high", "column": "fare_amount", "check": "spike",
     "message": "the value 70 went from 4.1% of the sample to 0.0% of the output"}
  ],
  "columns": [
    {"column": "fare_amount", "kind": "numeric", "ks": 0.061, "wassersteinIqr": 0.08,
     "percentiles": {"p1": [3.0, 3.1], "p50": [13.5, 13.9], "p99": [79.3, 70.2]},
     "min": [0.0, 0.0], "max": [250.0, 180.4],
     "spikes": [{"value": "70", "sampleShare": 0.041, "outputShare": 0.0}],
     "sampleExample": "13.5", "outputExample": "13.9"}
  ],
  "correlations": [
    {"columns": ["trip_distance", "fare_amount"], "sample": 0.94, "output": 0.93}
  ]
}
```

`findings` is sorted high, medium, low. `check` is one of `format`, `type`, `distribution`, `tails`, `range`, `spike`, `categories`, `repetition`, `privacy`, `correlation`. Per-column entries carry what applies to their kind (`distinct`, `tvd`, `categories`, `copiedFromSample`, `shapeMismatch`).

**Sample values in the report.** A comparison report tends to get pasted into notes, tickets and documentation, so it doesn't repeat values that could identify someone. Numeric columns and small category sets (up to 50 distinct values) show sample values as they are. Codes (NPIs, ZIP codes, account numbers) and other text (names, streets) show only a sample value's character pattern: `9` for a digit, `A` and `a` for letters, runs of letters collapsed, so `42 Oak Ave` shows as `99 Aa Aa` and the text report says `sample pattern`. A leading zero is kept (`09999`), because a lost one is a finding. JSON marks a pattern with `"sampleExampleIsPattern": true`. Generated values are always shown as they are. Use `--show-sample-values` to see the real values while working on your own machine.

## THE HTML REPORT AND THE CLASSIFIER SCORE

`--html report.html` writes the comparison as one self-contained page to share: no script and no external files, light and dark, and it prints. It holds a scorecard (findings by severity and the classifier score), the findings, a chart per column (overlaid histograms of the sample and the generated rows, a Q-Q plot of their percentiles and a percentile table for numbers; share bars of the commonest values for categories), and a heatmap of how each pair of numeric columns' rank correlation changed. It keeps the rule above: numbers appear only as bins and percentiles, a category value is named only when it fills at least 10 sample rows and the column is not a code, and a column with more than 200 different values (an identifier, free text) is not charted. `--show-sample-values` names every value.

The classifier score (`--score`, and in the report) is the area under the ROC curve of a logistic regression trained to tell sample rows from generated ones, by 5-fold cross-validation on up to 4,000 rows of each: 0.5 means it cannot tell them apart, 1.0 that it tells every row. Its features are each numeric column standardized and squared, the products of pairs of numeric columns, and each other column's 20 commonest sample values. The same classifier on two halves of the sample gives the score of a perfect copy, for scale. It sees means, spreads, pairwise relations and category shares but not every shape, so a low score is necessary for a close model, not proof of one. An identifier the model numbers 1, 2, 3 instead of copying makes the score 1.0 on its own: read it with the findings. The score is the same on every run for the same tables.

## EXIT STATUS

- **0**: compared; no high-severity finding.
- **1**: compared; at least one high-severity finding.
- **2**: bad arguments, a model or sample that can't be read or run, or a model whose output width doesn't match the sample's columns.

## EXAMPLES

Check a fitted model against the sample it was fitted to:

```
compare model.xml sample.csv
```

Against held-out rows, with a fixed seed, as JSON for a script:

```
compare --seed 1 --json model.xml holdout.csv > report.json
```

Gate a CI step on it:

```
compare --seed 1 model.xml sample.csv || exit 1
```

## SEE ALSO

[Grind.md](https://obsvra.com/docs/grind), [ModelValidatorApp.md](https://obsvra.com/docs/modelvalidatorapp), [ModelAnalyzerApp.md](https://obsvra.com/docs/modelanalyzerapp), [McpServerApp.md](https://obsvra.com/docs/mcpserverapp)
