来自 keras-beats 的 Nbeats 模型中的值错误

问题描述 投票:0回答:1

我正在尝试从 keras-beats 实现 NBeats 模型来进行时间序列预测,它向我显示了有关使用浮点数据类型的值错误。我尝试使用 astype 将数据转换为 float 32 和 64,但它仍然显示类似的错误

代码:
从 kerasbeats 导入 prep_time_series,NBeatsModel

#导入数据集

df = pd.read_csv('DailyDelhiClimateTrain.csv', parse_dates = ['日期'], index_col = '日期')

# 按日期排序

df.sort_index(inplace = True)

# 为 N-Beats 准备单变量时间序列

X, y = prep_time_series(df['meantemp'], 回溯 = 7, 地平线 = 1)

# 创建训练和测试集

从 sklearn.model_selection 导入 train_test_split

X_train,X_test,y_train,y_test = train_test_split(X,y,

shuffle = False,test_size = 0.2)

# 初始化 N-Beats 并适合

nbeats = NBeatsModel(model_type = '通用',回顾= 7,地平线= 1)

nbeats.fit(X,y)

错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[104], line 4
      1 X = X.astype('float64')
      2 y = y.astype('float64')
----> 4 nbeats.fit(X,y)

File ~\AppData\Roaming\Python\Python311\site-packages\kerasbeats\nbeats.py:384, in NBeatsModel.fit(self, X, y, **kwargs)
    382 """Build and fit model"""
    383 self.build_layer()
--> 384 self.build_model()
    385 self.model.compile(optimizer = keras.optimizers.Adam(self.learning_rate), 
    386                    loss      = [self.loss],
    387                    metrics   = ['mae', 'mape'])
    388 self.model.fit(X, y, batch_size = self.batch_size, **kwargs)

File ~\AppData\Roaming\Python\Python311\site-packages\kerasbeats\nbeats.py:376, in NBeatsModel.build_model(self)
    374 def build_model(self):
    375     """Creates keras model to use for fitting"""
--> 376     inputs     = keras.layers.Input(shape = (self.horizon * self.lookback, ), dtype = 'float')
    377     forecasts  = self.model_layer(inputs)
    378     self.model = Model(inputs, forecasts)

File ~\AppData\Roaming\Python\Python311\site-packages\keras\src\layers\core\input_layer.py:143, in Input(shape, batch_size, dtype, sparse, batch_shape, name, tensor)
     89 @keras_export(["keras.layers.Input", "keras.Input"])
     90 def Input(
     91     shape=None,
   (...)
     97     tensor=None,
     98 ):
     99     """Used to instantiate a Keras tensor.
    100 
    101     A Keras tensor is a symbolic tensor-like object, which we augment with
   (...)
    141     ```
    142     """
--> 143     layer = InputLayer(
    144         shape=shape,
    145         batch_size=batch_size,
    146         dtype=dtype,
    147         sparse=sparse,
    148         batch_shape=batch_shape,
    149         name=name,
    150         input_tensor=tensor,
    151     )
    152     return layer.output

File ~\AppData\Roaming\Python\Python311\site-packages\keras\src\layers\core\input_layer.py:49, in InputLayer.__init__(self, shape, batch_size, dtype, sparse, batch_shape, input_tensor, name, **kwargs)
     47     batch_shape = (batch_size,) + shape
     48 self.batch_shape = tuple(batch_shape)
---> 49 self._dtype = backend.standardize_dtype(dtype)
     51 self.sparse = bool(sparse)
     52 if self.sparse and not backend.SUPPORTS_SPARSE_TENSORS:

File ~\AppData\Roaming\Python\Python311\site-packages\keras\src\backend\common\variables.py:521, in standardize_dtype(dtype)
    518     dtype = dtype.__name__
    520 if dtype not in dtypes.ALLOWED_DTYPES:
--> 521     raise ValueError(f"Invalid dtype: {dtype}")
    522 return dtype

ValueError: Invalid dtype: float

我尝试将 dtype 更改为 float 32 和 64,但仍然不起作用。我只是期待模型适合数据。对于数据,我使用了 kaggle 上提供的气候变化数据

python tensorflow keras
1个回答
0
投票

你找到解决办法了吗?我这里也遇到同样的问题

© www.soinside.com 2019 - 2024. All rights reserved.