Nixtla / neuralforecast

Scalable and user friendly neural :brain: forecasting algorithms.
https://nixtlaverse.nixtla.io/neuralforecast
Apache License 2.0
2.69k stars 312 forks source link

Manually set horizon weights to different windows #939

Open Newaij0 opened 3 months ago

Newaij0 commented 3 months ago

Description

To my understanding, currently the implementation of horizon weights is by adding a fixed horizon_weight list when initializing the loss function.

horizon_weight = np.hstack((np.ones(10,)*2, np.ones(10,), np.ones(10,)*2))
horizon = 30 

model1 = TFT(h = horizon, 
             input_size = horizon*3,
             hidden_size = 64, 
             n_head = 4,
             loss = MAE(horizon_weight = horizon_weight),  ##
             valid_loss = MAE(), # MAE()
             learning_rate = 0.001,
             dropout = 0.1,
             attn_dropout = 0.1,
             futr_exog_list = futr_exog,
             hist_exog_list = hist_exog,
             stat_exog_list = stat_exog,
             max_steps = 600,
             val_check_steps = 50,  
             scaler_type = 'robust',
             batch_size = 128)

However in the case I'm dealing with, the loss during holidays is considered more important, not the distance between predicted timestamp and current timestamp.

I add a column to the input DataFrame representing the weight of each timestamp and try to modify the base window class to extract weights for different time windows. Is there any way to adding weight more easily?

Thanks

Use case

Setting different horizon weight to each window by simply adding a weight column in the input DataFrame.

elephaint commented 2 months ago

Thanks for the suggestion. While we consider it, options to account for different sample importances are: