0

Im turning around since a years with this problem, I want to forcast t+1 using the forcast t+0 as one of my input. All I find is running my model one step at time and manualy insert my last forcast in the input for the next one step run... not efficient and impossible to train.

I use keras with tensorflow. Thank for any help!

0

1 Answer 1

1

I suggest u ChainRegressor/Classifier from sklearn. as u specify this model iterate fit in each step using the previous predictions as features for the new fit. here an example in a regression task

import numpy as np
import tensorflow as tf
from tensorflow.keras.layers import *
from tensorflow.keras.models import *
from sklearn.multioutput import RegressorChain

n_sample = 1000
input_size = 20

X = np.random.uniform(0,1, (n_sample,input_size))
y = np.random.uniform(0,1, (n_sample,3)) <=== 3 step forecast

def create_model():
    
    global input_size
    
    model = Sequential([
        Dense(32, activation='relu', input_shape=(input_size,)),
        Dense(1)
    ])

    model.compile(optimizer='Adam', loss='mse')
    input_size += 1 # <== important 
    # increase the input dimension and include the previous predictions in each iteration
    
    return model

model = tf.keras.wrappers.scikit_learn.KerasRegressor(build_fn=create_model, epochs=1, 
                                                       batch_size=256, verbose = 1)
chain = RegressorChain(model, order='random', random_state=42)
chain.fit(X, y)

chain.predict(X).shape
Sign up to request clarification or add additional context in comments.

3 Comments

If I use lstm with seq of 5 last time step input, it can manage the last 5 forcast time step too?
you can manage and customize it according to your needs
I'm not familliar withsklearn, I have some difficultywith implementation my code/model is a bit complex.... but your solution seem excellent thank!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.