Marco
06/02/2025, 4:48 PMmlp = MLP(
h=12,
input_size=24,
max_steps=200,
alias="MLP"
)
nf = NeuralForecast(models=[mlp], freq="ME")
nf.fit(df=Y_train_df)
explanation = nf.explain(background_size=50, target_samples=5)
it returns a dict with all the values necessary for SHAP to make plots and interpret:
{'MLP': {'shap_values': array([[[-6.10306270e+01, -9.39689115e+00, 1.97515033e+01,
1.17820769e+01, 1.51813563e+01, 2.06414518e+01,
1.89970556e+01, 1.91416997e+01, 2.06474227e+01,
-5.95401884e+00, -4.46718962e+00, -2.44429846e+01],
...
'feature_names': ['y_lag_1',
'y_lag_2',
'y_lag_3',
'y_lag_4',
'y_lag_5',
'y_lag_6',
'y_lag_7',
'y_lag_8',
'y_lag_9',
'y_lag_10',
'y_lag_11',
'y_lag_12',
'y_lag_13',
'y_lag_14',
'y_lag_15',
'y_lag_16',
'y_lag_17',
'y_lag_18',
'y_lag_19',
'y_lag_20',
'y_lag_21',
'y_lag_22',
'y_lag_23',
'y_lag_24'],
'background_data': array([[640., 618., 662., 648., 663., 735., 791., 805., 704., 659., 610.,
637., 660., 642., 706., 696., 720., 772., 848., 859., 763., 707.,
662., 705.]], dtype=float32),
'target_data': array([[340., 318., 362., 348., 363., 435., 491., 505., 404., 359., 310.,
337., 360., 342., 406., 396., 420., 472., 548., 559., 463., 407.,
362., 405.]], dtype=float32),
'base_values': array([732.64758301, 707.97583008, 755.71826172, 754.11199951,
787.41577148, 853.30413818, 948.47595215, 924.73815918,
838.97302246, 759.78320312, 718.87841797, 737.99725342]),
'model_name': 'MLP',
'model_alias': 'MLP'}}
So then, we can make plots like the one attached.
It's still in progress. Next step is to also include exogenous features, not just past lags, but just wanted to get early feedback, in case you don't think it's worth continuing working on itHan Wang
06/02/2025, 5:20 PMOlivier Sprangers
06/02/2025, 5:21 PMHan Wang
06/02/2025, 5:23 PMOlivier Sprangers
06/02/2025, 5:26 PMMarco
06/02/2025, 6:00 PMOlivier Sprangers
06/02/2025, 6:01 PMMarco
06/02/2025, 6:06 PMHan Wang
06/02/2025, 6:20 PMNikhil Gupta
06/02/2025, 6:22 PMautoreg
, group price and discount related features as a category called price_related
, etc. and find the importance/contribution of each category?Han Wang
06/02/2025, 6:23 PMMarco
06/02/2025, 6:28 PMOlivier Sprangers
06/02/2025, 6:34 PMOlivier Sprangers
06/02/2025, 6:36 PMNikhil Gupta
06/02/2025, 6:44 PMHan Wang
06/02/2025, 6:46 PM