【问题标题】:Python Keras LSTM 'ValueError: `start_index+length='Python Keras LSTM 'ValueError: `start_index+length='
【发布时间】:2020-05-01 07:02:52
【问题描述】:

我正在尝试为 airpassenger 数据集实现 Keras LSTM。它会产生以下错误。

ValueError: `start_index+length=12 > end_index=11` is disallowed, as no part of the sequence would be left to be used as current step

这是我尝试过的。你能帮我找出问题吗?

import glob
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from statsmodels.tools.eval_measures import rmse
from keras.preprocessing.sequence import TimeseriesGenerator
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import Dropout
from sklearn.preprocessing import MinMaxScaler
import warnings
warnings.filterwarnings("ignore")

df = pd.read_csv('airline-passengers.csv')
df.Month = pd.to_datetime(df.Month)
df = df.set_index('Month')
train, test = df[-12:], df[:-12]
scaler = MinMaxScaler()
scaler.fit(train)
scaler.transform(train)
scaler.transform(test)
n_input = 12
n_features = 1
generator = TimeseriesGenerator(train, train, length=n_input, batch_size=6)
model = Sequential()
model.add(LSTM(200, activation='relu', input_shape=(n_input, n_features)))
model.add(Dropout(0.15))
model.add(Dense(1))
model.compile(loss='mse',optimizer='adam')
model.fit_generator(generator, epochs=100)

【问题讨论】:

    标签: python-3.x tensorflow keras keras-2


    【解决方案1】:

    我有同样的问题,我认为在你的情况下是因为你试图在 len = 12 的数据中使用长度 = 12,并且 TimeseriesGenerator 使用类似的目标每个序列的下一个值(这个值将是13,但你使用 len 12)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-23
      • 2017-08-28
      • 2020-07-08
      • 2021-03-08
      • 1970-01-01
      • 2016-12-07
      • 2018-11-06
      • 2020-05-25
      相关资源
      最近更新 更多