build_artifact
from compileml.artifact import build_artifact
Compile a fitted model into a complete, hashed decision artifact.
Args:
model: Fitted sklearn GBM, XGBoost, or LightGBM model whose raw
output is a probability-like latent in [0, 1] (distilled
whiteboxes always satisfy this; classifiers emitting log-odds
margins must be distilled first via train_whitebox, and are
now refused at extraction rather than compiled to a wrong base).
feature_names: Feature order the model was trained on.
baseline: Reference row (typically imputer medians): imputation
values under missing_policy="baseline" and the attribution
reference point.
band_edges: Float latent band edges (from compileml.bands builders),
converted here to the fixed-point ladder.
band_labels: Labels per band; defaults to G01..Gnn.
calibration_latent: Latent sample used to fit the isotonic PD table
(alternatively pass a prebuilt calibration block).
calibration_y: Binary outcomes aligned with calibration_latent.
reasons: Reason dictionary mapping feature name -> {code, negative,
positive, suppress}. **User-supplied content**: without an entry
a feature falls back to generic messages that are not suitable
for consumer-facing notices. Coverage below 100% warns and is
recorded in metadata (spec §7.6).
missing_policy: "baseline" (impute at decision time) or "reject".
monotone_constraints: Declared directions per feature: a sequence of
-1/0/+1 in feature order, or a dict keyed by feature name or
index. The compiled integer trees are *verified* against the
declaration (spec §3.1) — any violation raises, whatever
trainer produced the model — and the signs are recorded in the
artifact under model.monotone_constraints, covered by the
hash. Validation check 9 re-verifies on the artifact alone.
X_sample: Optional sample rows; enables the measured quantization
report and the latent-range check.
Returns: The artifact dict, hashed and structurally validated.
Parameters#
| Name | Type | Default | Kind |
|---|---|---|---|
| model | — | required | positional |
| feature_names | — | required | positional |
| baseline | — | required | positional |
| band_edges | — | required | positional |
| band_labels | — | None | keyword-only |
| calibration_latent | — | None | keyword-only |
| calibration_y | — | None | keyword-only |
| calibration | dict | None | None | keyword-only |
| calibration_mode | str | 'linear_int' | keyword-only |
| reasons | dict | None | None | keyword-only |
| display_names | dict | None | None | keyword-only |
| feature_meta | list | None | None | keyword-only |
| missing_policy | str | 'baseline' | keyword-only |
| monotone_constraints | — | None | keyword-only |
| metadata | dict | None | None | keyword-only |
| scale | int | 1000 | keyword-only |
| micro_scale | int | 1000000 | keyword-only |
| top_k | int | 5 | keyword-only |
| threshold_decimals | int | None | None | keyword-only |
| X_sample | — | None | keyword-only |
Returns#
dict
Raises#
- ValueError
Read from the function body and the private helpers it calls, not inferred. A function that raises nothing has no section here.
Example#
from compileml.artifact import build_artifact artifact = build_artifact( whitebox, feature_names, baseline=medians, band_edges=bands, calibration_latent=latent, calibration_y=y_train, reasons=REASON_DICTIONARY,)