1
1
#!/usr/bin/env python
2
- # Copyright (c) 2023, 2024 Oracle and/or its affiliates.
2
+ # Copyright (c) 2023, 2025 Oracle and/or its affiliates.
3
3
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
4
4
import logging
5
5
import os
@@ -66,8 +66,7 @@ def preprocess(self, data): # TODO: re-use self.le for explanations
66
66
@runtime_dependency (
67
67
module = "automlx" ,
68
68
err_msg = (
69
- "Please run `pip3 install oracle-automlx>=23.4.1` and "
70
- "`pip3 install oracle-automlx[forecasting]>=23.4.1` "
69
+ "Please run `pip3 install oracle-automlx[forecasting]>=25.1.1` "
71
70
"to install the required dependencies for automlx."
72
71
),
73
72
)
@@ -270,11 +269,15 @@ def _generate_report(self):
270
269
self .formatted_local_explanation = aggregate_local_explanations
271
270
272
271
if not self .target_cat_col :
273
- self .formatted_global_explanation = self .formatted_global_explanation .rename (
274
- {"Series 1" : self .original_target_column },
275
- axis = 1 ,
272
+ self .formatted_global_explanation = (
273
+ self .formatted_global_explanation .rename (
274
+ {"Series 1" : self .original_target_column },
275
+ axis = 1 ,
276
+ )
277
+ )
278
+ self .formatted_local_explanation .drop (
279
+ "Series" , axis = 1 , inplace = True
276
280
)
277
- self .formatted_local_explanation .drop ("Series" , axis = 1 , inplace = True )
278
281
279
282
# Create a markdown section for the global explainability
280
283
global_explanation_section = rc .Block (
@@ -423,7 +426,9 @@ def explain_model(self):
423
426
# Use the MLExplainer class from AutoMLx to generate explanations
424
427
explainer = automlx .MLExplainer (
425
428
self .models [s_id ],
426
- self .datasets .additional_data .get_data_for_series (series_id = s_id )
429
+ self .datasets .additional_data .get_data_for_series (
430
+ series_id = s_id
431
+ )
427
432
.drop (self .spec .datetime_column .name , axis = 1 )
428
433
.head (- self .spec .horizon )
429
434
if self .spec .additional_data
@@ -434,7 +439,9 @@ def explain_model(self):
434
439
435
440
# Generate explanations for the forecast
436
441
explanations = explainer .explain_prediction (
437
- X = self .datasets .additional_data .get_data_for_series (series_id = s_id )
442
+ X = self .datasets .additional_data .get_data_for_series (
443
+ series_id = s_id
444
+ )
438
445
.drop (self .spec .datetime_column .name , axis = 1 )
439
446
.tail (self .spec .horizon )
440
447
if self .spec .additional_data
@@ -446,7 +453,9 @@ def explain_model(self):
446
453
explanations_df = pd .concat (
447
454
[exp .to_dataframe () for exp in explanations ]
448
455
)
449
- explanations_df ["row" ] = explanations_df .groupby ("Feature" ).cumcount ()
456
+ explanations_df ["row" ] = explanations_df .groupby (
457
+ "Feature"
458
+ ).cumcount ()
450
459
explanations_df = explanations_df .pivot (
451
460
index = "row" , columns = "Feature" , values = "Attribution"
452
461
)
@@ -458,5 +467,7 @@ def explain_model(self):
458
467
# Fall back to the default explanation generation method
459
468
super ().explain_model ()
460
469
except Exception as e :
461
- logger .warning (f"Failed to generate explanations for series { s_id } with error: { e } ." )
470
+ logger .warning (
471
+ f"Failed to generate explanations for series { s_id } with error: { e } ."
472
+ )
462
473
logger .debug (f"Full Traceback: { traceback .format_exc ()} " )
0 commit comments