【问题标题】:What does the function predict of the Tensorflow Model do with a regression problem leveraging a RNNTensorflow 模型的函数预测对利用 RNN 的回归问题有什么作用
【发布时间】:2021-01-08 23:28:03
【问题描述】:

我正在研究一个时间序列问题并且我训练了一个模型 与财务数据。在网的训练过程中表现非常好。

现在我在问如何预测未来的 FORWARD 使用 Tensorflow 模型对新数据集进行预测函数的结果是什么。下面的 sn-p 显示了预测函数的调用

def predict(self, data=None ):
                            
    model =  tf.keras.models.load_model(self.createModelFileName())
                    
    scaler = MinMaxScaler()
    feature_scaler = MinMaxScaler()
       
    data.loc[:, data.columns != self.feature] = scaler.fit_transform(data.loc[:, data.columns != self.feature])
    data[[self.feature]] = feature_scaler.fit_transform(data[[self.feature]])    
    inputs = data[1:] 
  
    inputs = np.expand_dims(inputs, axis=0)
    print(f'Shape data: {data}')
    print(f'Shape inputs: {inputs.shape}')        
        
    prediction = model.predict(inputs, 32, steps=5, verbose=1)
                   
    print(prediction.shape)
    
    data[[self.feature]] = feature_scaler.inverse_transform(data[[self.feature]])
    inputs = np.array(data[self.feature])
    
    prediction = prediction[0,:,:]        
    print(prediction.shape)    
    prediction = feature_scaler.inverse_transform(prediction)
                                                                
    return inputs, prediction  

我所做的图只是显示了使用任意偏移对过去输入的预测,而不是对未来的预测。

我知道自动回归这个术语,我也尝试过,通过使用最后的预测值扩展预测函数的输入。

【问题讨论】:

    标签: python-3.x tensorflow machine-learning


    【解决方案1】:

    您必须查看最后一个序列索引。假设您的序列维度为 1:

    prediction = prediction[:,-1,:]        
    

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 2020-07-07
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 2019-03-20
      • 1970-01-01
      相关资源
      最近更新 更多