Types¶
Bucket¶
Bucket
dataclass
¶
Bucket(bucket_type: BucketType, index: int, lower: float = float('-inf'), upper: float = float('inf'), categories: Optional[frozenset] = None, mean_shap: Optional[float] = None)
A single bucket for a feature.
For numeric features: defined by [lower, upper) interval. For null bucket: lower=upper=NaN. For categorical: categories is a frozenset of category values.
contains
¶
Check if a value falls into this bucket.
Source code in src/swift/types.py
BucketSet¶
BucketSet
dataclass
¶
BucketSet(feature_name: str, buckets: tuple[Bucket, ...] = tuple(), decision_points: ndarray = (lambda: array([]))())
Collection of buckets for a single feature.
Attributes: feature_name: Name of the feature. buckets: List of Bucket objects (including null bucket). decision_points: Sorted array of decision points (split thresholds).
assign_bucket
¶
Return the index of the bucket that contains the given value.
Raises: ValueError: If the value does not fall into any bucket.
Source code in src/swift/types.py
get_mean_shap
¶
Return the mean SHAP value for the given bucket index.
Raises: KeyError: If the bucket index does not exist.
Source code in src/swift/types.py
BucketType¶
BucketType
¶
Bases: Enum
Type of bucket.
WassersteinOrder¶
WassersteinOrder
¶
Bases: Enum
Order of Wasserstein distance.
CorrectionMethod¶
CorrectionMethod
¶
Bases: Enum
Multiple testing correction method.
Supports construction from strings via CorrectionMethod.resolve(),
so users can write correction="benjamini-hochberg" instead of
importing the enum.
resolve
classmethod
¶
resolve(value: CorrectionMethod | str) -> CorrectionMethod
Return a CorrectionMethod from a member, its value, or an alias.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Enum member, canonical string (
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CorrectionMethod
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If value cannot be resolved. |
Source code in src/swift/types.py
FeatureSWIFTResult¶
FeatureSWIFTResult
dataclass
¶
FeatureSWIFTResult(feature_name: str, swift_score: float, wasserstein_order: WassersteinOrder = W1, p_value: Optional[float] = None, is_drifted: Optional[bool] = None, num_buckets: int = 0)
SWIFT result for a single feature.
Attributes: feature_name: Name of the feature. swift_score: SWIFT score (Wasserstein distance on SHAP-transformed distributions). wasserstein_order: Which Wasserstein order was used (W1 or W2). p_value: p-value from permutation or bootstrap test (None if not computed). is_drifted: Whether the feature is flagged as drifted after correction. num_buckets: Number of buckets used.
SWIFTResult¶
SWIFTResult
dataclass
¶
SWIFTResult(feature_results: tuple[FeatureSWIFTResult, ...], swift_max: float, swift_mean: float, swift_weighted: Optional[float] = None, alpha: float = 0.05, correction_method: Optional[CorrectionMethod] = None)
Aggregate SWIFT result across all features.
Attributes: feature_results: Per-feature results. swift_max: Maximum SWIFT score across features. swift_mean: Mean SWIFT score across features. swift_weighted: Importance-weighted SWIFT score (optional). alpha: Significance level used for testing. correction_method: Multiple testing correction method used.