I am trying to implement NBeats model from keras-beats for timeseries prediction forcasting and it shows me valueerror about using float data type. I tried using astype to convert data to float 32 and 64 and it still showed me similar error
code:
from kerasbeats import prep_time_series, NBeatsModel
# import the dataset
df = pd.read_csv(‘DailyDelhiClimateTrain.csv’, parse_dates = [‘date’], index_col = ‘date’)
# sort by dates
df.sort_index(inplace = True)
# prep a univariate time series for N-Beats
X, y = prep_time_series(df[‘meantemp’], lookback = 7, horizon = 1)
# create training and test sets
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y,
shuffle = False, test_size = 0.2)
# initialize N-Beats and fit
nbeats = NBeatsModel(model_type = ‘generic’, lookback = 7, horizon = 1)
nbeats.fit(X,y)
Error:
---------------------------------------------------------------------------
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 ~AppDataRoamingPythonPython311site-packageskerasbeatsnbeats.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 ~AppDataRoamingPythonPython311site-packageskerasbeatsnbeats.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 ~AppDataRoamingPythonPython311site-packageskerassrclayerscoreinput_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 ~AppDataRoamingPythonPython311site-packageskerassrclayerscoreinput_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 ~AppDataRoamingPythonPython311site-packageskerassrcbackendcommonvariables.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
I tried changing dtype to float 32 and 64 and it still didnt work. I was just expecting model to fit the data. For data I have used climate change daata available at kaggle
Priyanshu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.