首页 > 解决方案 > TF CuDNNLSTM 最小值始终高于 0,即使在训练数据为 0 时...就像它被移位了 + 5

问题描述

基本上我已经尝试过这段代码

np.random.seed(7)
            dataframe = read_csv('c:/data/suicides.csv', usecols=[1], engine='python')
            dataset = dataframe.values
            dataset = dataset.astype('float32')

                # normalize the dataset
            scaler = MinMaxScaler(feature_range=(0, 1))
            dataset = scaler.fit_transform(dataset)

                # split into train and test sets
            train_size = int(len(dataset) * 0.67)
            test_size = len(dataset) - train_size
            train, test = dataset[0:train_size,:], dataset[train_size:len(dataset),:]

            # reshape into X=t and Y=t+1
            look_back = 1
            trainX, trainY = create_dataset(train, look_back)
            testX, testY = create_dataset(test, look_back)

                # reshape input to be [samples, time steps, features]
            trainX = np.reshape(trainX, (trainX.shape[0], trainX.shape[1], 1))
            testX = np.reshape(testX, (testX.shape[0], testX.shape[1], 1))


                            # Initialising the RNN
            #regressor = Sequential()
            model = Sequential()

            # # In[25]:


            # # Adding the first LSTM layer and some Dropout regularisation
            model.add(CuDNNLSTM(units = 10, return_sequences = True, input_shape = (trainX.shape[1], 1)))
            model.add(Dropout(0.1))


            # # In[26]:


            # # Adding a second LSTM layer and some Dropout regularisation
            model.add(CuDNNLSTM(units = 5, return_sequences = True))
            model.add(Dropout(0.1))


            # # In[27]:


            # # Adding a third LSTM layer and some Dropout regularisation
            model.add(CuDNNLSTM(units = 4, return_sequences = True))
            model.add(Dropout(0.1))


            # # In[28]:


            # ## Adding a fourth LSTM layer and some Dropout regularisation
            model.add(CuDNNLSTM(units = 2))
            model.add(Dropout(0.2))


            # # In[29]:


            # # Adding the output layer
            model.add(Dense(units = 1))


            # # In[30]:


            # # Compiling the RNN
            model.compile(optimizer = 'adam', loss = 'mean_squared_error')


            # # In[33]:

            #     #epoch = [10, 15, 20, 25, 30, 35, 40, 45, 50]

            # # Fitting the RNN to the Training set
            model.fit(trainX, trainY, epochs = _epoch, batch_size = _batch)



            # make predictions
            trainPredict = model.predict(trainX)
            testPredict = model.predict(testX)

不幸的是,由于某种原因,虽然有很长的时间序列 0,但它不会预测为零。

曾经。训练/测试数据的最小值/最大值从 0 开始,但预测数据的最小值始终为 5-6。价值。

训练/测试数据从 0 - ~ 40

我尝试了不同的设置、时期数、激活、优化器、损失,但总是最小。预测数据的值 > ~ 最大训练值的 15%....

标签: tensorflowkeras

解决方案


由于某种原因,时间序列中大于 1 的批次会产生过高的最小预测。

通过修改批量设置+模型训练设置来解决。

因此,如果您的预测 > 0,则可能是训练设置有问题。


推荐阅读