@@ -413,41 +413,45 @@ def explain_model(self):
413413 for s_id , data_i in self .datasets .get_data_by_series (
414414 include_horizon = False
415415 ).items ():
416- if self .spec .explanations_accuracy_mode == SpeedAccuracyMode .AUTOMLX :
417- # Use the MLExplainer class from AutoMLx to generate explanations
418- explainer = automlx .MLExplainer (
419- self .models [s_id ],
420- self .datasets .additional_data .get_data_for_series (series_id = s_id )
421- .drop (self .spec .datetime_column .name , axis = 1 )
422- .head (- self .spec .horizon )
423- if self .spec .additional_data
424- else None ,
425- pd .DataFrame (data_i [self .spec .target_column ]),
426- task = "forecasting" ,
427- )
416+ try :
417+ if self .spec .explanations_accuracy_mode == SpeedAccuracyMode .AUTOMLX :
418+ # Use the MLExplainer class from AutoMLx to generate explanations
419+ explainer = automlx .MLExplainer (
420+ self .models [s_id ],
421+ self .datasets .additional_data .get_data_for_series (series_id = s_id )
422+ .drop (self .spec .datetime_column .name , axis = 1 )
423+ .head (- self .spec .horizon )
424+ if self .spec .additional_data
425+ else None ,
426+ pd .DataFrame (data_i [self .spec .target_column ]),
427+ task = "forecasting" ,
428+ )
428429
429- # Generate explanations for the forecast
430- explanations = explainer .explain_prediction (
431- X = self .datasets .additional_data .get_data_for_series (series_id = s_id )
432- .drop (self .spec .datetime_column .name , axis = 1 )
433- .tail (self .spec .horizon )
434- if self .spec .additional_data
435- else None ,
436- forecast_timepoints = list (range (self .spec .horizon + 1 )),
437- )
430+ # Generate explanations for the forecast
431+ explanations = explainer .explain_prediction (
432+ X = self .datasets .additional_data .get_data_for_series (series_id = s_id )
433+ .drop (self .spec .datetime_column .name , axis = 1 )
434+ .tail (self .spec .horizon )
435+ if self .spec .additional_data
436+ else None ,
437+ forecast_timepoints = list (range (self .spec .horizon + 1 )),
438+ )
438439
439- # Convert the explanations to a DataFrame
440- explanations_df = pd .concat (
441- [exp .to_dataframe () for exp in explanations ]
442- )
443- explanations_df ["row" ] = explanations_df .groupby ("Feature" ).cumcount ()
444- explanations_df = explanations_df .pivot (
445- index = "row" , columns = "Feature" , values = "Attribution"
446- )
447- explanations_df = explanations_df .reset_index (drop = True )
440+ # Convert the explanations to a DataFrame
441+ explanations_df = pd .concat (
442+ [exp .to_dataframe () for exp in explanations ]
443+ )
444+ explanations_df ["row" ] = explanations_df .groupby ("Feature" ).cumcount ()
445+ explanations_df = explanations_df .pivot (
446+ index = "row" , columns = "Feature" , values = "Attribution"
447+ )
448+ explanations_df = explanations_df .reset_index (drop = True )
448449
449- # Store the explanations in the local_explanation dictionary
450- self .local_explanation [s_id ] = explanations_df
451- else :
452- # Fall back to the default explanation generation method
453- super ().explain_model ()
450+ # Store the explanations in the local_explanation dictionary
451+ self .local_explanation [s_id ] = explanations_df
452+ else :
453+ # Fall back to the default explanation generation method
454+ super ().explain_model ()
455+ except Exception as e :
456+ logger .warning (f"Failed to generate explanations for series { s_id } with error: { e } ." )
457+ logger .debug (f"Full Traceback: { traceback .format_exc ()} " )
0 commit comments