简体   繁体   English

如何训练在线回归模型

[英]How to train an online regression model

I have a dataset with shape (9430, 12) .我有一个形状为(9430, 12)的数据集。 The problem comes when fitting: all 12 features are my X and my Y .拟合时出现问题:所有12特征都是我的X和我的Y I mean, it's an online learning model where I train my data[i] and then predict data[i+1] .我的意思是,这是一个在线学习模型,我训练我的data[i]然后预测data[i+1] So as you can see, and as I said before, Y = X .正如你所看到的,正如我之前所说, 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?如果是,我还能如何训练它?

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.鉴于Y[0] = X[0]、Y[1] = X[1]等。

You should move the window frame by one in the Ys matrix.您应该在 Ys 矩阵中将窗框移动一位。 For example, imagine that X is a numpy array, you can do:例如,假设 X 是一个 numpy 数组,你可以这样做:

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.此代码将实现: Y[0] = X[1] , Y[1] = X[2] ,这是能够在每个点预测下一个的期望输出。

Once you have the two tensors ready you can fit your model with Tensorflow or Keras.准备好两个张量后,您就可以使用 Tensorflow 或 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.请记住,Ys 矩阵中的最后一行只是一个 0 的虚拟行,因为您不知道下一步的基本事实是什么。 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.此外,对于预测序列数据,循环神经网络(如LSTM、长短期记忆)更合适。 I suggest you take a look at them :)我建议你看看他们:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM