我有预测项目,我正在尝试预测时间序列中的下一个值。我使用的是Python 2.7.x,Keras 2.0.4和Theano 0.9.0。
我想通过预测给定第一个X-1点的时间序列的每个最后X点的值来评估模型,然后对预测误差求平均值。
假设我总共有10个数据点,而我的X = 4。第一个模型将根据前6个数据点的知识构建,并用于预测第7个点。 然后我想将第7点添加到模型中以预测第8点,但不必完全重新训练模型。
在下面的演示代码中,我使用数字1到10作为时间序列数据
import math
import numpy
from keras.models import Sequential
from keras.layers import Dense
# The time series points in this demo are the numbers 1 to 10
x_train = [(1,2), (2,3), (3,4), (4,5)]
y_train = [3, 4, 5, 6]
x_test = [(5, 6)]
y_test = [7]
# Create NN model and train on original training data set
nn = Sequential()
nn.add(Dense(2, input_dim=2, activation='relu')) # Input/Hidden layer
nn.add(Dense(1)) # Output layer
nn.compile(loss='mean_squared_error', optimizer='adam')
nn.fit(x_train, y_train, epochs=100, batch_size=2)
prediction = nn.predict(numpy.array(x_test))[0][0]
abs_error = math.fabs(prediction - y_test)
# TODO How do I fit the model to the (x_test, y_test) data to improve the model without
# retraining from scratch ?
# Below is my best guess. If value of epoch is 1 then the model only 'sees' the new point
# once while it has seen the other points 100 times (#epochs above). But if I set it to
# 100 I fear the model will skew heavily towards the new point.
nn.fit(x_test, y_test, initial_epoch=100, epochs='1 OR 100 OR SomethingElseCompletely ?', batch_size=1)
# TODO Predict next_y based on next_x
考虑到上述情况,我是完全偏离基础还是可以为NN添加额外的训练点?