为什么Keras没有概括我的数据?

问题描述 投票:0回答:1

我一直在尝试实现一个基本的多层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]]]

我如何格式化这个,以便当我插入一个具有完全不同比例的值的序列时,网络仍将输出其预测值?我已经尝试将我的训练数据标准化,但结果仍然完全无法使用。

我在这做错了什么?

machine-learning tensorflow keras lstm recurrent-neural-network
1个回答
0
投票

如何在发送到LSTM之前转换输入数据,使用sklearn.preprocessing.StandardScaler之类的东西?预测后你可以调用scaler.inverse_transform(预测)

© www.soinside.com 2019 - 2024. All rights reserved.