0

我刚刚开始使用 LSTM 时间序列预测示例。

在最后一步出现以下错误,不确定我在这里缺少什么。任何帮助将不胜感激!.ERROR- NameError: name 'to_list' is not defined

def split_sequence(sequence, n_steps):
X, y = list(), list()
for i in range(len(sequence)):
    # find the end of this pattern
    end_ix = i + n_steps
    # check if we are beyond the sequence
    if end_ix > len(sequence)-1:
        break
    # gather input and output parts of the pattern
    seq_x, seq_y = sequence[i:end_ix], sequence[end_ix]
    X.append(seq_x)
    y.append(seq_y)
return array(X), array(y)

# define input sequence
raw_seq = [10, 20, 30, 40, 50, 60, 70, 80, 90]
# choose a number of time steps
n_steps = 3

# split into samples
X, y = split_sequence(raw_seq, n_steps)
# reshape from [samples, timesteps] into [samples, timesteps, features]
n_features = 1
X = X.reshape((X.shape[0], X.shape[1], n_features))
# define model
model = Sequential()
model.add(LSTM(50, activation='relu', input_shape=(n_steps, n_features)))
#----ERROR AT THIS STEP-----------------------------------------
4

1 回答 1

0

谢谢阿拉特。是的,这段代码来自 Jason 的 LSTM 教程。缩进是正确的,我检查了几次。看起来可能与 Keras 软件包版本有关,因为这只是区别。我使用的是 Keras 2.1.5。你用的是哪个版本的 Keras?

于 2019-01-24T05:53:36.110 回答