0

我一直在尝试实现一个基本的多层LSTM回归网络来找出加密电子货币价格之间的相关性。Keras为什么不能概括我的数据?

在遇到无法使用的训练结果后,我决定尝试使用一些沙盒代码,以确保在重试完整数据集之前我已经明白了。

问题是我不能让凯拉斯推广我的数据。

ts = 3 
in_dim = 1 

data = [i*100 for i in range(10)] 

# tried this, didn't accomplish anything 
# data = [(d - np.mean(data))/np.std(data) for d in data] 

x = data[:len(data) - 4] 
y = data[3:len(data) - 1] 

assert(len(x) == len(y)) 

x = [[_x] for _x in x] 
y = [[_y] for _y in y] 

x = [x[idx:idx + ts] for idx in range(0, len(x), ts)] 
y = [y[idx:idx + ts] for idx in range(0, len(y), ts)] 

x = np.asarray(x) 
y = np.asarray(y) 

X看起来是这样的:

[[[ 0] 
    [100] 
    [200]] 

[[300] 
    [400] 
    [500]]] 

和y:

[[[300] 
    [400] 
    [500]] 

[[600] 
    [700] 
    [800]]] 

这个效果很好,当我预测使用非常相似的数据集,但不会推广的时候我尝试使用缩放值类似的顺序

model = Sequential() 

model.add(BatchNormalization(
    axis = 1, 
    input_shape = (ts, in_dim))) 

model.add(LSTM(
    100, 
    input_shape = (ts, in_dim), 
    return_sequences = True)) 

model.add(TimeDistributed(Dense(in_dim))) 
model.add(Activation('linear')) 
model.compile(loss = 'mse', optimizer = 'rmsprop') 

model.fit(x, y, epochs = 2000, verbose = 0) 

p = np.asarray([[[10],[20],[30]]]) 
prediction = model.predict(p) 
print(prediction) 

打印

[[[ 165.78544617] 
    [ 209.34489441] 
    [ 216.02174377]]] 

我想

[[[ 40.0000] 
    [ 50.0000] 
    [ 60.0000]]] 

我怎么能格式化这个所以,当我在一个序列插头是一个完全不同的刻度值,网络仍然会输出它的预测值?我试着对训练数据进行规范化处理,但结果仍然完全无法使用。

我在这里做了什么错?

+0

我还发现这个关于使用LSTM对单变量数据进行自回归的讨论很有用:https://machinelearningmastery.com/suitability-long-short-term-memory-networks - 时间序列预测/ - 不能说它完全回答了我的问题,但它提供了一些有关LSTM如何不能达到时间序列预测预期的见解。 – Phil

+0

你高估了深度学习的力量。你只给它乘以100作为输入,并期望它也推广到10的倍数。因为10不是特殊数字,所以这种转换学习也应该适用于任何数字的整数倍数。但是,您的模型应该如何知道这是它应该完成的任务?你的训练数据决不会告诉你。任务也可以是在当前时间步骤简单地将100添加到输入。为了能够推广,您需要提供包含泛化示例的模型训练数据。 –

回答

0

如何在发送到您的LSTM之前转换您的输入数据,使用类似sklearn.preprocessing.StandardScaler?经过预测,你可以打电话给scaler.inverse_transform(预测)

相关问题