OK 400
OK 400

Reputation: 831

How to train an online regression model

I have a dataset with shape (9430, 12). The problem comes when fitting: all 12 features are my X and my Y. I mean, it's an online learning model where I train my data[i] and then predict data[i+1]. So as you can see, and as I said before, Y = X.

data.shape = (9430, 12)
Y = X = data.values
model.fit(X, Y)

Is this wrong? If yes, how else could I train it?

Upvotes: 0

Views: 166

Answers (1)

rodvictor
rodvictor

Reputation: 339

I understand that your objective is that, at each time step, you would like to predict the input of the next time step.

Right now you are trying to predict the same output as you are passing as input. Given that Y[0] = X[0], Y[1] = X[1], and so on.

You should move the window frame by one in the Ys matrix. For example, imagine that X is a numpy array, you can do:

import tensorflow as tf
Y = tf.concat((np.copy(X[1:,:]),np.zeros((1,12))), axis=0)
X = tf.convert_to_tensor(X)

This code will achieve: Y[0] = X[1] , Y[1] = X[2], which is the desired output for being able to predict, at each point, the following one.

Once you have the two tensors ready you can fit your model with Tensorflow or Keras. Please bear in mind that the last row in the Ys matrix is just a dummy row of 0s given that you do not know what is the ground truth for the following step. Probably you should skip it from your dataset when performing training.

Also, for predicting sequential data, Recurrent Neural Networks (such as LSTM, Long Short Term Memory) are more appropriate. I suggest you take a look at them :)

Upvotes: 2

Related Questions