Slackbot
12/25/2023, 9:27 PMMax (Nixtla)
12/26/2023, 1:50 AMChristiaan
12/26/2023, 7:58 AMCristian (Nixtla)
12/26/2023, 4:06 PMavailable_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.Christiaan
12/26/2023, 4:15 PMCristian (Nixtla)
12/26/2023, 4:41 PMnf.models[0].train_trajectories
and nf.models[0].valid_trajectories
Christiaan
01/16/2024, 10:42 AMCristian (Nixtla)
01/16/2024, 7:46 PMChristiaan
01/17/2024, 2:59 PMCristian (Nixtla)
01/18/2024, 7:01 PMCristian (Nixtla)
01/18/2024, 7:01 PMChristiaan
01/18/2024, 8:37 PMChristiaan
01/25/2024, 5:29 PMChristiaan
01/25/2024, 5:29 PMimport 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()
Christiaan
01/31/2024, 7:17 PM