0

I am just getting started with LSTM time series forecasting example.

Getting a below error at the last step, not sure what am i missing here. Any help would be greatly appreciated!.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-----------------------------------------
RSingh
  • 51
  • 1
  • 6
  • It does not throw any error to me since this is a code which can be found online. Be careful with indents in `split_sequence` function. – ARAT Jan 24 '19 at 00:10

1 Answers1

0

Thanks Arat. Yes this code is from Jason’s LSTM tutorials. Indentation is correct, I checked couple of times. It looks like issue maybe with Keras package version because that is only difference.I am using Keras 2.1.5. Which version are you using for Keras?

RSingh
  • 51
  • 1
  • 6