compileml.artifact

build_artifact

def build_artifact(model, feature_names, baseline, band_edges, *, band_labels=None, calibration_latent=None, calibration_y=None, calibration: dict | None = None, calibration_mode: str = 'linear_int', reasons: dict | None = None, display_names: dict | None = None, feature_meta: list | None = None, missing_policy: str = 'baseline', monotone_constraints=None, metadata: dict | None = None, scale: int = 1000, micro_scale: int = 1000000, top_k: int = 5, threshold_decimals: int | None = None, X_sample=None) -> dict

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#

NameTypeDefaultKind
model—requiredpositional
feature_names—requiredpositional
baseline—requiredpositional
band_edges—requiredpositional
band_labels—Nonekeyword-only
calibration_latent—Nonekeyword-only
calibration_y—Nonekeyword-only
calibrationdict | NoneNonekeyword-only
calibration_modestr'linear_int'keyword-only
reasonsdict | NoneNonekeyword-only
display_namesdict | NoneNonekeyword-only
feature_metalist | NoneNonekeyword-only
missing_policystr'baseline'keyword-only
monotone_constraints—Nonekeyword-only
metadatadict | NoneNonekeyword-only
scaleint1000keyword-only
micro_scaleint1000000keyword-only
top_kint5keyword-only
threshold_decimalsint | NoneNonekeyword-only
X_sample—Nonekeyword-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#

python
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,
)

Worked example: build_artifact →