Config & YAML¶
Declarative suite loading and the custom-test registry.
modeltest.config
¶
Declarative suite definition: load a ModelSuite from YAML.
The YAML format mirrors the built-in scenarios with a type and params:
.. code-block:: yaml
suite:
name: "Credit Scoring Model"
tests:
- type: minimum_accuracy
params:
threshold: 0.85
- type: group_performance
params:
metric: accuracy
threshold: 0.8
group_col: "gender"
- type: robustness
params: {noise_std: 0.01, max_drop: 0.03}
- type: data_drift
params: {features: [age, income], max_psi: 0.15}
- type: equal_opportunity
params: {protected_col: "gender", max_diff: 0.1}
- type: statistical_parity
params: {protected_col: "gender", max_diff: 0.1, min_ratio: 0.8}
- type: feature_dominance
params: {max_top_share: 0.9}
- type: top_features
params: {expected_features: [income, age], k: 2}
- type: confidence_threshold
params: {metric: accuracy, threshold: 0.85, n_boot: 1000, alpha: 0.05}
- type: data_invariant
params: {expected_columns: [age, income], max_null_ratio: 0.02}
load_suite_yaml(path)
¶
Build a :class:ModelSuite from a YAML file.
Raises ValueError for unknown test types or malformed structure.
Source code in modeltest/config.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
dump_suite_yaml(suite, path)
¶
Serialise a suite back to YAML (best-effort; only built-in tests).
Source code in modeltest/config.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
register(type_name, cls)
¶
Map a YAML type string to a custom test class.
Custom tests must subclass :class:modeltest.ModelTest. Registering
before :func:load_suite_yaml lets a suite reference your test by name::
from modeltest.config import register
register("my_error_check", MyErrorCheck)
# suite.yaml
# suite:
# tests:
# - type: my_error_check
# params: {max_errors: 5}
Source code in modeltest/config.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
unregister(type_name)
¶
Remove a previously registered type (built-ins included).
Source code in modeltest/config.py
96 97 98 | |
modeltest.cli
¶
Command-line interface: modeltest validate.
main(argv=None)
¶
Entry point for the modeltest console script.
Args:
argv: Command-line arguments (defaults to sys.argv[1:]).
Returns:
Process exit code: 0 when the validated suite passes, 1
when any test fails.
Source code in modeltest/cli.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |