website/reference/commands/modeling.md
Use xpd modeling to review model family choices, grouped or hierarchical predictors, validation splitters, CV hyperparameter optimization, asymmetric scoring, baseline comparisons, calibration, MAPIE conformal or quantile-forest uncertainty, and post-fit explanations (shap, fippy, effector) in Python. The list inventories named estimators, evaluation reports, and CV wrappers across scikit-learn, glum, quantile_forest, skore, scikit-lego, MAPIE, LightGBM, XGBoost, optuna_integration, skrub, Nixtla (MLForecast, StatsForecast), statsmodels, and linearmodels. It forwards selected pack reports (including glum, quantile_forest, skore, shap, fippy, effector, optuna, optuna_integration, sklego, skfolio, mlforecast, utilsforecast, mapie, sklearn, lightgbm, and xgboost) and adds local advisories about scaling, split conflicts, baseline comparisons, and quantile scoring.
List and catalog
| 1 | $ xpd modeling --questions --format json | jq -c '[.questions[].id]' |
| 2 | ["model-family","grouped-predictors","validation-scheme","cv-optimization","baseline-comparison","metric-and-loss","feature-exclusions","probability-calibration","uncertainty-and-conformal","first-failure","model-explanation","pipeline-evidence"] |
The catalog includes measured facts, checklist questions, and MCP gate names. Listing the catalog runs no project code.
Run xpd modeling <paths> --limit 0 --format json to list findings, inventory, and checklist. Add --adapter adapter.py for runtime measurements. Repeat the recorded paths and adapter when listing during a run. read.models identifies each model by file and qualified binding. The stable model ID prefixes its checklist IDs. Resolved findings include a model ID. With no adapter, read.facts is null. Adapter errors appear under read.facts.error and leave the static list available. Recorded stages require valid measurements when an adapter is configured and enforce checklist evidence rules on plan, gate, and finish.
Adapter
A Python adapter defines models() and returns an iterable of mappings.
| Field | Meaning |
|---|---|
file, binding | A selected Git-root-relative Python file and a qualified binding such as train.model. Give factories and adapter-only models distinct bindings. |
X, y, estimator | Row-aligned development data and an unfitted estimator. Exclude any final test set. |
scorer, splitter | A scikit-learn scorer name, callable (estimator, X, y) -> float (such as make_scorer(..., greater_is_better=False)), or (name, callable), plus the splitter name used to materialize folds. Higher is always better. |
secondary_scorers | Optional mapping of additional scorer names or callables evaluated on the exact same validation rows per fold. |
folds | Mappings with a unique string id, integer positional fit and validation indices, and optional early_stopping and calibration indices. Roles must be disjoint within each fold. |
baseline | Optional unfitted estimator. Defaults to a prior classifier or mean regressor. Both estimators use the exact same fit and validation rows. |
candidates | Optional mapping {name: unfitted_estimator} (or (estimator, fit_fold)) fitted and scored on the exact same folds and primary scorer to compare model families and grouped/hierarchical predictors directly. |
groups, times | Optional row-aligned group IDs and UTC timestamps. The report shows group intersections, time boundaries, purge/embargo gaps, conflicts, and per-group validation scores (group_performance). |
positive_label | Required to measure binary Brier loss, log-loss, ECE, and five reliability bins. Multiclass classifiers compute top-label reliability bins, multiclass Brier, log-loss, and ECE automatically. |
fit_fold | Optional callback taking (cloned_estimator, X_fit, y_fit, X_stop, y_stop) and returning the fitted estimator. |
conformalize | Optional split-conformal callback (fitted, X_cal, y_cal) requiring a nonempty calibration partition. Return an object with predict_interval, predict_set, or predict. |
conformalize_fit | Optional cross-conformal / jackknife+ / EnbPI / ACI callback (X_fit, y_fit) that requires no separate calibration partition. Return an object with predict_interval, predict_set, or predict. |
confidence_levels | Distinct confidence levels in (0, 1), required whenever conformalize or conformalize_fit is provided. |
A shell adapter prints one JSON document with the same models array as the Python runner. Every measured model includes file, binding, scorer, splitter, baseline, estimator_profile, folds (with partitions.purge_gap, residuals, group_performance, and optional secondary_scores / candidates), spread, probability_calibration (Brier, log-loss, ECE, bins), interval_coverage (pooled and per-fold coverage, width/set size, Winkler/MWI score, SSC, singleton/empty set rates), and optional candidate_summary. Unavailable measurements include a reason.
Recorded Python adapters must be committed in the repository. Recorded adapters run from the root of the selected commit on both sides of a comparison. Project Python logs go to stderr.
Recorded stages
| Command | Result |
|---|---|
xpd modeling start | Record the clean tracked baseline, paths, checks and optional adapter. |
xpd modeling <paths> | List current models, findings, facts and questions. |
xpd modeling plan | Record fixes, acceptance reasons and validated checklist verdicts. |
xpd modeling gate | Evaluate one committed fix against the last kept commit and invalidate stale answers. |
xpd modeling finish | Compare with the starting commit and close the run. |
xpd modeling status | Show the run and next stage. |
xpd modeling approve | Approve a fix that changes an interface. |
xpd modeling drop | Record why a fix was abandoned. |
Recorded example
A quantile model predicts at 0.9. The score mistakenly uses a pinball loss at 0.1.
| 1 | from sklearn.ensemble import GradientBoostingRegressor |
| 2 | from sklearn.metrics import mean_pinball_loss |
| 3 | |
| 4 | |
| 5 | def score_quantile(x_fit, y_fit, x_validation, y_validation): |
| 6 | model = GradientBoostingRegressor(loss="quantile", alpha=0.9, random_state=7) |
| 7 | model.fit(x_fit, y_fit) |
| 8 | return mean_pinball_loss(y_validation, model.predict(x_validation), alpha=0.1) |
The example initializes a scratch Git repository. It prints the next stage or fix outcome after each successful command and the refusal message when a fix or an answer is open.
| 1 | $ git init -q && git -c user.name=Example -c user.email=example@example.com add bad.py && git -c user.name=Example -c user.email=example@example.com commit -qm initial |
| 2 | $ xpd modeling start bad.py --check "git diff --check" --format json | jq -r .next.stage |
| 3 | plan |
| 4 | $ xpd modeling bad.py --limit 0 --format json | jq -c '[.advice[].kind]' |
| 5 | ["metric-loss-mismatch"] |
| 6 | $ xpd modeling bad.py --limit 0 --format json | jq '{fixes:[{id:"pinball",title:"Score the intended quantile",findings:[.advice[] | select(.kind == "metric-loss-mismatch") | .id]}]}' > plan.json |
| 7 | $ xpd modeling plan plan.json --format json | jq -r .next.stage |
| 8 | fix |
| 9 | $ xpd modeling finish --format json 2>&1 >/dev/null |
| 10 | xpd: the fix pinball is still open |
| 11 | $ python -c 'from pathlib import Path; p = Path("bad.py"); p.write_text(p.read_text().replace("alpha=0.1", "alpha=0.9"))' && git -c user.name=Example -c user.email=example@example.com commit -qam 'Score the intended quantile' |
| 12 | $ xpd modeling gate pinball --format json | jq -r '.run.rounds[-1][0].outcome' |
| 13 | kept |
| 14 | $ xpd modeling finish --format json 2>&1 >/dev/null | cut -d: -f1-2 |
| 15 | xpd: these checklist items are unanswered |
| 16 | $ xpd modeling bad.py --format json | jq '{answered:[.checklist[] | {item:.id,verdict:"accepted",reason:"Scratch example with no deployment; validation design remains unverified."}]}' | xpd modeling plan - --format json | jq -r .next.stage |
| 17 | plan |
| 18 | $ xpd modeling finish --format json 2>/dev/null | jq -r .next.stage |
| 19 | finished |
See the model review guide for the review sequence.
Exit status
| Status | Meaning |
|---|---|
| 0 | A successful stage or list. JSON stage output contains run and next. |
| 1 | A rejected gate, open fix, unanswered question or unexplained new finding. |
| 2 | An invocation or adapter error. |