Aggregation¶
aggregation
¶
Stage 6: Aggregation — feature-level to model-level SWIFT scores.
Provides three aggregation strategies from the paper (§3.6): - Maximum SWIFT: most-drifted feature (SWIFT_max) - Mean SWIFT: average feature drift (SWIFT_mean) - Weighted SWIFT: importance-weighted (SWIFT_weighted)
Functions: aggregate_scores: Compute model-level summary statistics. compute_importance_weights: Normalized mean |SHAP| weights w_j.
AggregatedScores
dataclass
¶
AggregatedScores(swift_max: float, swift_mean: float, max_feature: str, swift_weighted: Optional[float] = None)
Model-level SWIFT aggregation.
Attributes: swift_max: Maximum per-feature SWIFT score. swift_mean: Unweighted mean of per-feature scores. swift_weighted: Importance-weighted score (None if no weights). max_feature: Name of the feature with the highest score.
aggregate_scores
¶
aggregate_scores(scores: dict[str, float], weights: dict[str, float] | None = None) -> AggregatedScores
Aggregate per-feature SWIFT scores to model level.
Args: scores: Dict of feature_name → SWIFT score. weights: Optional dict of feature_name → importance weight. If provided, weights should sum to 1 (or be normalizable). If None, swift_weighted is set to None.
Returns: AggregatedScores with max, mean, and optionally weighted score.
Source code in src/swift/aggregation.py
compute_importance_weights
¶
Compute normalized mean absolute SHAP importance weights.
w_j = |φ̄_j| / Σ_k |φ̄_k|
where φ̄_j = mean(|SHAP_j(x_i)|) across all reference observations.
This generalizes SSI's IV-based weights with model-aware SHAP-based feature importance.
Args: shap_values: SHAP values array of shape (n, p). feature_names: List of p feature names.
Returns: Dict of feature_name → weight (non-negative, sums to 1).