When working with multiple CatBoost models wrapped in CalibratedClassifierCV, extracting feature importances, SHAP values, and interaction strengths requires careful handling of the underlying models and consideration of consistency challenges. Here’s a structured approach:
1. Feature Importances
CatBoost provides multiple methods to calculate feature importance. For ensemble models:
- Access base models: Extract the 5 CatBoost classifiers from
CalibratedClassifierCV.calibrated_classifiers_.
- Aggregate importances: Compute feature importance for each base model and average the results. Use methods like:
PredictionValuesChange: Default for non-ranking tasks, measures average prediction change per feature[3].
LossFunctionChange: Suitable for ranking tasks, evaluates loss impact when omitting a feature[3].
ShapValues: Directly outputs SHAP-based importance[3].
# Example: PredictionValuesChange for each model
importances = []
for calibrated_model in calibrated_classifier.calibrated_classifiers_:
model = calibrated_model.base_estimator
importances.append(model.get_feature_importance(type='PredictionValuesChange'))
average_importances = np.mean(importances, axis=0)
2. SHAP Values
SHAP values explain individual predictions but face challenges with calibrated outputs:
- Per-model SHAP: Use
shap.TreeExplainer on each base CatBoost model and average contributions[1][6]. This avoids calibration complexities.
- Full pipeline SHAP: For explanations of calibrated probabilities, use
shap.KernelExplainer on the entire CalibratedClassifierCV (slower but more accurate)[2].
# Per-model SHAP (faster)
shap_values_list = []
for calibrated_model in calibrated_classifiers:
explainer = shap.TreeExplainer(calibrated_model.base_estimator)
shap_values_list.append(explainer.shap_values(X))
average_shap = np.mean(shap_values_list, axis=0)
# Full pipeline SHAP (slower)
explainer = shap.KernelExplainer(calibrated_classifier.predict_proba, X_background)
shap_values = explainer.shap_values(X)
3. Feature Interaction Values
CatBoost’s interaction strength metric quantifies pairwise feature dependencies[3][8]:
- Per-model interactions: Compute interactions for each base model and aggregate.
- Interpretation: Higher values indicate stronger interactions.
interaction_strengths = []
for calibrated_model in calibrated_classifiers:
model = calibrated_model.base_estimator
interaction_strength = model.get_feature_importance(type='Interaction')
interaction_strengths.append(interaction_strength)
average_interactions = np.mean(interaction_strengths, axis=0)
4. Addressing Consistency Concerns
Recent research highlights limitations in SHAP’s faithfulness for tree models:
- PGI squared: A perturbation-based metric proposed as a more faithful alternative[4]. Implement custom code to compute it for your models.
- Cross-validation: Compare results across multiple importance methods (e.g.,
PredictionValuesChange vs. SHAP) to identify stable features[5].
Key Recommendations
- Prefer base model explanations: Calibration primarily adjusts probabilities, so base model importances/SHAP values often suffice.
- Leverage CatBoost’s native methods: They are optimized for speed and accuracy compared to third-party tools[3][6].
- Validate with multiple metrics: Use SHAP, PGI squared, and built-in CatBoost metrics to triangulate trustworthy results[4][5].
For categorical features, CatBoost’s native handling ensures SHAP values are computed per categorical feature (not per one-hot-encoded column), simplifying interpretation[6].