Schemas and result objects
Import configuration and result schemas from:
from model_auditor.schemas import ( AuditorFeature, AuditorOutcome, AuditorScore, CalibrationEvaluation, ConditionalThreshold, FeatureEvaluation, LevelEvaluation, LevelMetric, InferenceConfig, ScoreEvaluation, ThresholdSpec,)The classes are mutable dataclasses. Snippets that use field(default_factory=...) assume field from dataclasses.
Configuration schemas
Section titled “Configuration schemas”InferenceConfig
Section titled “InferenceConfig”InferenceConfig controls confidence level, automatic versus bootstrap
interval selection, Wilson versus exact binomial rates, IID/stratified/cluster
resampling, cluster ID, local random seed, missing-feature policy, and minimum
valid-resample thresholds. It is also exported from model_auditor.
AuditorFeature
Section titled “AuditorFeature”@dataclassclass AuditorFeature: name: str label: str | None = Nonename: DataFrame column and internal dictionary key.label: human-readable feature text.
ConditionalThreshold
Section titled “ConditionalThreshold”@dataclassclass ConditionalThreshold: feature: str levels: dict[Any, float] default: float | None = Nonefeature: column used for row-level threshold selection.levels: native feature-value to threshold mapping.default: optional fallback for unmapped or null feature values.
Validation occurs during evaluation, not dataclass construction.
ThresholdSpec
Section titled “ThresholdSpec”ThresholdSpec = float | ConditionalThresholdThe runtime resolver also attempts float(value) for scalar candidates, then rejects non-finite results.
AuditorScore
Section titled “AuditorScore”@dataclassclass AuditorScore: name: str label: str | None = None threshold: ThresholdSpec | None = Nonethreshold=None is valid registration state, but threshold-dependent evaluation later requires a stored or call-time specification.
AuditorOutcome
Section titled “AuditorOutcome”@dataclassclass AuditorOutcome: name: str mapping: dict[Any, int] | None = NoneAuditor uses the dataclass to call add_outcome() and materialize _truth.
LevelMetric
Section titled “LevelMetric”@dataclassclass LevelMetric: name: str label: str score: float | int interval: tuple[float, float] | None = None status: str = "ok" interval_status: str = "not_requested" interval_method: str | None = None denominator: int | None = None valid_resamples: int = 0 requested_resamples: int = 0 nonfinite_resamples: int = 0 direction: str | None = None parameters: dict = field(default_factory=dict)This is the atomic ordinary result. Diagnostic fields explain undefined estimates and withheld intervals without guessing from NaN alone.
scoreis numeric.intervalstores lower and upper bounds for eligible observed metrics.- Count metrics and categorical placeholders generally have no interval.
LevelEvaluation
Section titled “LevelEvaluation”@dataclassclass LevelEvaluation: name: str metrics: dict[str, LevelMetric] = field(default_factory=dict)LevelEvaluation.update
Section titled “LevelEvaluation.update”update( metric_name: str, metric_label: str, metric_score: float,) -> NoneCreates or replaces one metric under metrics[metric_name].
LevelEvaluation.update_intervals
Section titled “LevelEvaluation.update_intervals”update_intervals( metric_intervals: dict[str, tuple[float, float]],) -> NoneSets intervals on existing metrics.
LevelEvaluation.to_dataframe
Section titled “LevelEvaluation.to_dataframe”to_dataframe( n_decimals: int = 3, add_index: bool = False, metric_labels: bool = False,) -> pd.DataFrameReturns one display-formatted row.
add_index is unused at this level in v0.1.16.
Formatting:
- CI metric:
score (lower, upper); - float without CI: fixed decimals;
- integer: comma-delimited integer text.
LevelEvaluation.style_dataframe
Section titled “LevelEvaluation.style_dataframe”style_dataframe( n_decimals: int = 3, metric_labels: bool = False, include_count_metrics: bool = False, low_color: str = "#f8d7da", medium_color: str = "#fff3cd", high_color: str = "#d4edda", rank: bool = False,) -> pd.io.formats.style.StylerStyling is neutral unless rank=True. A single-row table has no useful
comparative tier context even though the method is available.
FeatureEvaluation
Section titled “FeatureEvaluation”@dataclassclass FeatureEvaluation: name: str label: str levels: dict[str, LevelEvaluation] = field(default_factory=dict) excluded_n: int = 0 total_n: int = 0FeatureEvaluation.update
Section titled “FeatureEvaluation.update”update( metric_name: str, metric_label: str, data: dict[str, float],) -> NoneAdds one metric across a level-to-score mapping.
FeatureEvaluation.update_intervals
Section titled “FeatureEvaluation.update_intervals”update_intervals( level_name: str, metric_intervals: dict[str, tuple[float, float]],) -> NoneUpdates one level’s intervals.
FeatureEvaluation.to_dataframe
Section titled “FeatureEvaluation.to_dataframe”to_dataframe( n_decimals: int = 3, add_index: bool = False, metric_labels: bool = False,) -> pd.DataFrameReturns one display-formatted row per level.
With add_index=True, the feature label becomes an outer index level.
FeatureEvaluation.style_dataframe
Section titled “FeatureEvaluation.style_dataframe”Has the same arguments as LevelEvaluation.style_dataframe(), applied across the feature’s levels.
ScoreEvaluation
Section titled “ScoreEvaluation”@dataclassclass ScoreEvaluation: name: str label: str features: dict[str, FeatureEvaluation] = field(default_factory=dict) metadata: dict = field(default_factory=dict)ScoreEvaluation.to_dataframe
Section titled “ScoreEvaluation.to_dataframe”to_numeric_dataframe() returns unrounded long-form estimates, support,
diagnostics, stable identifiers, and a copy of provenance in
frame.attrs["metadata"].
to_dataframe( n_decimals: int = 3, add_index: bool = False, metric_labels: bool = False,) -> pd.DataFrameReturns a display-formatted table with feature label and level name as the row MultiIndex.
With add_index=True, the score label becomes an additional outer index.
ScoreEvaluation.style_dataframe
Section titled “ScoreEvaluation.style_dataframe”style_dataframe( n_decimals: int = 3, metric_labels: bool = False, include_count_metrics: bool = False, low_color: str = "#f8d7da", medium_color: str = "#fff3cd", high_color: str = "#d4edda", rank: bool = False,) -> pd.io.formats.style.StylerStyling is neutral unless rank=True. Ranking is computed within each feature,
not across unrelated feature dimensions.
ScoreEvaluation.plot_metric_intervals
Section titled “ScoreEvaluation.plot_metric_intervals”plot_metric_intervals( metric: str, feature_names: list[str] | None = None, include_overall: bool = True, rotate_plots: bool = False, include_sample_size: bool = True, include_class_balance: bool = True,) -> dict[str, tuple[Figure, Axes]]See Plotting API for behavior and errors.
Ordering and placeholders
Section titled “Ordering and placeholders”For pandas categorical features:
levelsdictionary order follows declared category order;- all declared categories appear;
- an unobserved category receives a
LevelEvaluation; - every selected metric is present with
score=NaN; and - intervals remain
None.
The result hierarchy preserves that order in tables and plots that consume the hierarchy.
For non-categorical features, ordinary metric and error evaluation convert level values to strings and use pandas’ default sorted group order. This is normally lexicographic order of the normalized string keys, not first-appearance order. Score-distribution plots are different: they preserve first appearance for non-categorical levels.
Styling helper behavior
Section titled “Styling helper behavior”The ordinary style methods classify known count names by exact, case-insensitive matching. TPR, TNR, FPR, and FNR are not misclassified as counts.
Each metric’s direction metadata controls ranking. A direction of "none"
suppresses performance color.
Tiers are based on strict percentile rank:
lower thirdmiddle thirdupper thirdNaN values receive no tier style.