Skip to content

Commit 71efc26

Browse files
authored
Explanation fixes for error and output generation. (#1090)
2 parents 4294649 + 208c811 commit 71efc26

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

‎ads/opctl/operator/lowcode/forecast/model/automlx.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ def _generate_report(self):
249249
self.explain_model()
250250

251251
global_explanation_section = None
252-
253252
# Convert the global explanation data to a DataFrame
254253
global_explanation_df = pd.DataFrame(self.global_explanation)
255254

@@ -470,13 +469,22 @@ def explain_model(self):
470469
self.global_explanation[s_id] = dict(
471470
zip(
472471
self.local_explanation[s_id].columns,
473-
np.nanmean((self.local_explanation[s_id]), axis=0),
472+
np.nanmean(np.abs(self.local_explanation[s_id]), axis=0),
474473
)
475474
)
476475
else:
477476
# Fall back to the default explanation generation method
478477
super().explain_model()
479478
except Exception as e:
479+
if s_id in self.errors_dict:
480+
self.errors_dict[s_id]["explainer_error"] = str(e)
481+
self.errors_dict[s_id]["explainer_error_trace"] = traceback.format_exc()
482+
else:
483+
self.errors_dict[s_id] = {
484+
"model_name": self.spec.model,
485+
"explainer_error": str(e),
486+
"explainer_error_trace": traceback.format_exc(),
487+
}
480488
logger.warning(
481489
f"Failed to generate explanations for series {s_id} with error: {e}."
482490
)

‎ads/opctl/operator/lowcode/forecast/model/base_model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ def _save_report(
570570
# explanations csv reports
571571
if self.spec.generate_explanations:
572572
try:
573-
if self.formatted_global_explanation is not None:
573+
if not self.formatted_global_explanation.empty:
574574
write_data(
575575
data=self.formatted_global_explanation,
576576
filename=os.path.join(
@@ -586,7 +586,7 @@ def _save_report(
586586
f"Attempted to generate global explanations for the {self.spec.global_explanation_filename} file, but an issue occured in formatting the explanations."
587587
)
588588

589-
if self.formatted_local_explanation is not None:
589+
if not self.formatted_local_explanation.empty:
590590
write_data(
591591
data=self.formatted_local_explanation,
592592
filename=os.path.join(

0 commit comments

Comments
 (0)