This message was deleted.
# neural-forecast
s
This message was deleted.
m
Hi, you can create those unique series by doing some data wrangling and creating a data frame with columns: date, unique_id, value. Where each unique id corresponds to the respective “cuts”: Series 1, Series 2, etc. That being said I see no obvios reason on why you would do something like that. What is your intuition behind handling the “same” series as many different ones? More “traditional” ways of handling nans is either replacing with zeros (eg retail) or interpolating.
c
Hey, thank you very much for the quick reply! It is an intuitive idea to try out for my masters thesis. I'm interested to see if there are better methods to handle missing values for my dataset. About 25% of all my rows are Nan values and if there are many consecutive Nan values, a forward fill or linear interpolation would destroy some of the pattern of the data and thus i'd be scared that the forecasting model has a more difficulty picking up the pattern. On the other hand, I can see how many the interpolations and ffills can make the model more robust as well.
c
Hi @Christiaan! The train dataframe has the option to pass an
available_mask
binary column, with 0s for the missing values. In addition to input with ffill, you can set the mask to 0 and the model wont use those timestamps in the train loss.
c
Very nice, thank you! In addition, another question: where can I find an overview of the losses made by the model during training?
c
Do you mean the training loss curves? You can get them from
nf.models[0].train_trajectories
and
nf.models[0].valid_trajectories
c
Hey guys, another question. All models predict over the entire forecasting horizon n. Is it also possible to predict n times a one step ahead model and then compute the average loss over the n prediction steps?
c
Hi @Christiaan. I didn't understand the difference, sorry. If you predict the same timestamps multiple times it will always return the same value.
c
Hey, what I mean is: you can have a model that predicts over an entire horizon or you use a model that predicts each time step of the horizon seperately. For example maybe one can predict per batch that is sampled from the dataloader iteratively the horizon with one step ahead model (instead of directly the entire horizon). Then average the losses and update the parameters. So in pseudocode: For x ,y in dataloader: Loss =0 For I in horizon_length: Yhat=predict_onestep(x,I) Loss+=compute_loss(y,yhat) End loop over horizon_length Loss/=horizon Update_params(Loss) End loop of dataloader Is that possible too?
c
So I believe that having the loss inside the for loop or outside will have equal values. It is more efficient to compute the loss once for the whole window given that we are operating with tensors. The other aspect is the recursive vs direct/joint strategy to produce forecasts, which is fixed by the type of model you are using. For instance, NBEATS, NHITS, and all transformers produce forecasts at once by design. The only recursive model with the for loop (that concatenates the last prediction as inputs to forecast the next timestamp) is DeepAR
hopes this answers your question 🙂
c
Thank you a lot! More questions will follow :))
Hey, another question. I am playing with NeuralForecast and want to do a recursive 1-step ahead regression using the MLP. However the predictions tremendously spiral out of control. Is that normal?
Copy code
import numpy as np
import pandas as pd
from IPython.display import display, Markdown

import matplotlib.pyplot as plt
from neuralforecast import NeuralForecast
from neuralforecast.models import MLP
from neuralforecast.utils import AirPassengersDF

# Split data and declare panel dataset
Y_df = AirPassengersDF
Y_df['noise'] = np.random.normal(0, 1, len(Y_df))
Y_train_df = Y_df[Y_df.ds<='1959-8-31'] # 
Y_test_df = Y_df[Y_df.ds>'1959-8-31'] # 

# Fit and predict with mlp
horizon = 1
models = [MLP(input_size=4,futr_exog_list=['noise'] ,h=horizon, max_steps=50)]

nf = NeuralForecast(models=models, freq='M')
nf.fit(df=Y_train_df)

# make a df to roll over and edit the y column with the predictions of the model
df_test_roller = Y_test_df.copy().reset_index()

# recursively predict the next value and put it to the df_test_roller
for i in range(len(Y_test_df)-1):

    # predict the next value
    Y_hat_df_i = nf.predict(df=df_test_roller.iloc[i: i+1], futr_df=df_test_roller.drop(columns='y').iloc[i+1: i+2]).reset_index()

    # replace the y column with the predicted value
    df_test_roller['y'].iloc[i+1] = Y_hat_df_i.iloc[0]['MLP']

fig, ax = plt.subplots(figsize=(15, 5))
ax.plot(Y_train_df['ds'], Y_train_df['y'], label='y')
ax.plot(Y_test_df['ds'], Y_test_df['y'], label='y')
ax.plot(Y_test_df['ds'], df_test_roller['y'], label='yhat')
ax.legend()
ax.grid()
fig.show()
@Cristian (Nixtla)