Slackbot
12/27/2023, 2:24 AMCristian (Nixtla)
12/27/2023, 4:47 PMhorizon=1
. The model is only learning to forecast the next timestamp, and could explain the behavior on the plot. With cross_validation
the forecasts are rolled, using the latest true value available (t-1 in this case because horizon is 1.Cristian (Nixtla)
12/27/2023, 4:48 PMAutoNHITS
to see how it compares?Layon Hu
01/02/2024, 5:31 AMimport <http://plotly.io|plotly.io> as pio
pio.renderers.default = 'browser'
import optuna
import pandas as pd
import datetime
import warnings
warnings.filterwarnings("ignore")
import matplotlib.pyplot as plt
from neuralforecast.core import NeuralForecast
from neuralforecast.models import NHITS
from neuralforecast.losses.pytorch import DistributionLoss, MQLoss
data = pd.read_csv("IMF6.csv")
data['ds'] = <http://pd.to|pd.to>_datetime(data['ds'], unit='s')
val_size = 64*320
test_size = 64*320
models = [NHITS(
h = horizon,
input_size = 40,
futr_exog_list= [
'railway',
'SPEED',
],
hist_exog_list=None,
stat_exog_list=None,
exclude_insample_y=False,
stack_types = ["identity", "identity", "identity"],
n_blocks = [1, 1, 1],
mlp_units = 2 * [[128, 128]],
n_pool_kernel_size = [16, 8, 1],
n_freq_downsample = [24, 12, 1],
pooling_mode = "MaxPool1d",
interpolation_mode = "linear",
dropout_prob_theta= 0.0,
activation="ReLU",
loss=DistributionLoss(distribution="Normal", level=[60, 90], return_params=False),
valid_loss=MQLoss(level=[60, 90]),
max_steps = 1600,
learning_rate = 0.00011156,
num_lr_decays = 3,
early_stop_patience_steps = -1,
val_check_steps = 100,
batch_size = 20,
valid_batch_size = None,
windows_batch_size = 64,
inference_windows_batch_size = -1,
start_padding_enabled=False,
step_size = 1,
scaler_type = "robust",
random_seed = 1,
num_workers_loader=0,
drop_last_loader=False,
)
]
nf = NeuralForecast(models=models, freq='s')
Y_hat_df = nf.cross_validation(df=data, val_size=val_size,
test_size=test_size, n_windows=None)