【问题标题】:date and time values for prediction预测的日期和时间值
【发布时间】:2019-09-18 02:35:30
【问题描述】:

我正在开发一个项目,用于按日期和时间预测 -1 到 1 之间的值。 我有一个包含 100 个预测值的数据集,我将数据拆分为 70 个训练集和 30 个测试集。 数据包含:日期和时间(2019-04-25 21:00:00)和预测(-1 到 1 值)

当我尝试在火车上调用 fit_transform 时,我收到了一个错误:

"ValueError: 预期二维数组,得到一维数组:array=[-1.-1. 1.-1。 -1。 -1。 -1。 -1。 -1。 -1。 -1。 -1。 -1。 1.-1。 1.-1。 1. 1.-1。 1.-1。 -1。 -1。 -1。 -1。 -1。 1.-1。 -1。 -1。 1.-1。 -1。 -1。 -1。 -1。 -1。 1.-1。 -1。 -1。 -1。 -1。 -1。 -1。 1.-1。 -1。 -1。 1.-1。 -1。 -1。 -1。 -1.]。如果您的数据具有单个特征,则使用 array.reshape(-1, 1) 或 array.reshape(1, -1) 重塑您的数据 包含一个样本。”

   df = pd.read_csv(file_to_read)
   df['Date']=pd.to_datetime(df['Date'])
   df=df.set_index(['Date'],drop=True)
   print(df.head(size))

   #Index for prediction 
   pred_index=int((size*30)/100)
   from_specific_time=df.index[pred_index]

   split_date=pd.Timestamp(from_specific_time)
   df=df['Predict']
   train=df.loc[split_date:]
   test=df.loc[:split_date]

   plt.figure(figsize=(10,6))
   ax=train.plot()
   test.plot(ax=ax)
   plt.legend(['train','test'])

   scaler=MinMaxScaler(feature_range=(-1,1))
   train_scaler=scaler.fit_transform(train)
   test_scaler=scaler.transform(test)

我想在 csv 中按确切时间创建一个时间序列,然后预测测试值..我不确定我做错了什么.. 顺便说一句,我正在学习教程:https://towardsdatascience.com/an-introduction-on-time-series-forecasting-with-simple-neura-networks-lstm-f788390915b

谢谢!

【问题讨论】:

  • 您在使用 MinMaxScaler 之前尝试过 train.values.reshape(-1, 1) 吗?

标签: python keras deep-learning time-series prediction


【解决方案1】:

错误表明它需要一个二维数组。所以尝试将数组转换为二维,

train = ([train])
train_scaler = scaler.fit_transform(train)

【讨论】:

    猜你喜欢
    • 2018-06-08
    • 2022-11-19
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 2016-11-27
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    相关资源
    最近更新 更多