我的初始数据是:
[[ 8375.5 0. 8374.14285714 8374.14285714] [ 8354.5 0. 8383.39285714 8371.52380952] ... [11060. 0. 11055.21428571 11032.53702732] [11076.5 0. 11061.60714286 11038.39875701]]
我创建MinMax缩放器,将数据转换为从0到1的值
scaler = MinMaxScaler(feature_range = (0, 1)) T = scaler.fit_transform(T)
现在的数据是:
[[0.5186697 , 0. , 0.46812344, 0.46950912], [0.5161844 , 0. , 0.46935928, 0.46915412], ..., [0.72264636, 0. , 0.6767292 , 0.6807525 ], [0.7198651 , 0. , 0.6785377 , 0.6833385 ]]
我做了一些魔术来准备LSTM层的数据,结果如下:
X_形状变量(6989, 4, 200)
[[[0.5186697 0. 0.46812344 ... 0. 0.45496237 0.45219505] [0.48742527 0. 0.45273864 ... 0. 0.43144143 0.431924 ] [0.4800284 0. 0.43054438 ... 0. 0.425362 0.4326681 ] [0.5007989 0. 0.4290794 ... 0. 0.4696839 0.47831726]] ... [[0.61240304 0. 0.57254803 ... 0. 0.5749577 0.57792616] [0.61139715 0. 0.5746571 ... 0. 0.5971378 0.6017289 ] [0.6365465 0. 0.59772 ... 0. 0.62671924 0.63145673] [0.65719867 0. 0.62684333 ... 0. 0.6757128 0.6772785 ]]]
我使用这个模型处理数据,末尾有Dense(1)
层:
model = Sequential() model.add(LSTM(units = 50, activation = 'relu', #return_sequences = True, input_shape = (X_train.shape[1], window_size))) model.add(Dropout(0.2)) model.add(Dense(1, activation = 'linear')) model.compile(loss = 'mean_squared_error', optimizer = 'adam')
- 当我将
return_sequences
设置为false
时,fit
之后的新数据的形状是(6989, 1)
,当我想使用这个标量反转scaler.inverse_transform(train_predict)
时,我得到一个错误:
ValueError: non-broadcastable output operand with shape (6989,1) doesn't match the broadcast shape (6989,4)
- 当我将
return_sequences
设置为true
时,新形状为(6989, 4, 1)
,而当我反转transform时,我得到了其他错误:
ValueError: Found array with dim 3. None expected <= 2.
============
我想我知道为什么会出现这些错误,因为定标器需要(6989,4)
的形状,但我如何转换这些数据,以便能够inverse_transform
?
- 如何反转
(6989, 1)
新形状的数据 - 如何反转
(6989, 4, 1)
新形状的数据
这可行吗?我的定标器可以使用吗?或者我应该创建新的缩放器?你能提出一些建议吗?我错过了什么?
我将感谢任何帮助,谢谢!