Mercurial > repos > goeckslab > pycaret_predict
comparison feature_importance.py @ 11:4eca9d109de1 draft default tip
planemo upload for repository https://github.com/goeckslab/gleam commit 55deacbbc78a00f27d789e11d563ba49dfb9cf9e
author | goeckslab |
---|---|
date | Fri, 22 Aug 2025 21:13:30 +0000 |
parents | 1aed7d47c5ec |
children |
comparison
equal
deleted
inserted
replaced
10:e2a6fed32d54 | 11:4eca9d109de1 |
---|---|
134 max_bg = min(len(X_data), 100) | 134 max_bg = min(len(X_data), 100) |
135 bg = X_data.sample(max_bg, random_state=42) | 135 bg = X_data.sample(max_bg, random_state=42) |
136 | 136 |
137 predict_fn = model.predict_proba if hasattr(model, "predict_proba") else model.predict | 137 predict_fn = model.predict_proba if hasattr(model, "predict_proba") else model.predict |
138 | 138 |
139 explainer = shap.Explainer(predict_fn, bg) | 139 try: |
140 self.shap_model_name = explainer.__class__.__name__ | 140 explainer = shap.Explainer(predict_fn, bg) |
141 | 141 self.shap_model_name = explainer.__class__.__name__ |
142 shap_values = explainer(X_data) | 142 |
143 shap_values = explainer(X_data) | |
144 except Exception as e: | |
145 LOG.error(f"SHAP computation failed: {e}") | |
146 self.shap_model_name = None | |
147 return | |
143 | 148 |
144 output_names = getattr(shap_values, "output_names", None) | 149 output_names = getattr(shap_values, "output_names", None) |
145 if output_names is None and hasattr(model, "classes_"): | 150 if output_names is None and hasattr(model, "classes_"): |
146 output_names = list(model.classes_) | 151 output_names = list(model.classes_) |
147 if output_names is None: | 152 if output_names is None: |