Nixtla / neuralforecast

Scalable and user friendly neural :brain: forecasting algorithms.
https://nixtlaverse.nixtla.io/neuralforecast
Apache License 2.0
2.69k stars 312 forks source link

TIDE Help | AttributeError: 'DataFrame' object has no attribute 'temporal_cols' #1005

Closed da1k-matter closed 1 month ago

da1k-matter commented 1 month ago

Hi guys! I just started to understand NeuralForecast, everything is very convenient, but it is not clear, what temporal_cols are required? I didn't find anything like that in the documentation, my dataset structure seems to be normal. Please help! I'm kind of new to ML/NeuralForecast at the moment.

Columns: Index(['ds', 'open', 'high', 'low', 'close', 'volume', 'kama', 'y'], dtype='object')

Dataset: ds open high ... volume kama y 22 2023-12-15 01:50:00 42999.9 43017.2 ... 101.493 42998.398417 -0.00049 23 2023-12-15 01:55:00 42975.3 43007.5 ... 154.853 42998.489312 0.00021 24 2023-12-15 02:00:00 43006.6 43036.6 ... 85.132 42998.604067 0.00027 25 2023-12-15 02:05:00 43003.0 43026.9 ... 92.799 42998.049372 -0.00129 26 2023-12-15 02:10:00 42962.0 42962.0 ... 460.089 42989.881402 -0.01900

Code:

import numpy as np
import pandas as pd
import talib
from neuralforecast.auto import AutoTiDE

config = dict(max_steps=2, val_check_steps=1, input_size=12)
model = AutoTiDE(h=3, num_samples=10, cpus=1, config=config)  # Specify the time column

dataset = pd.read_csv('Datasets/BTCUSDT_5m.csv')
dataset['kama'] = talib.KAMA(dataset['close'], timeperiod=21)
dataset['kslope'] = np.round(np.insert(np.diff(dataset['kama']), 0, 0) / dataset['kama'] * 100, 5)
dataset.rename(columns={'timestamp': 'ds', 'kslope': 'y'}, inplace=True)
dataset['ds'] = pd.to_datetime(dataset['ds'])
dataset.dropna(inplace=True)

model.fit(dataset=dataset)
y_hat = model.predict(dataset=dataset)

Errors:

--> AttributeError: 'DataFrame' object has no attribute 'temporal_cols'
2024-05-12 17:58:16,701 
ERROR tune_controller.py:1331 -- Trial task failed for trial _train_tune_58054_00004
--> 2024-05-12 17:58:16,834 WARNING experiment_analysis.py:558 -- Could not find best trial. Did you pass the correct `metric` parameter?

Traceback:

(_train_tune pid=90050) Seed set to 1
2024-05-12 17:58:16,695 ERROR tune_controller.py:1331 -- Trial task failed for trial _train_tune_58054_00006
.....
  File "/Users/ryzzhkovtom/miniconda3/envs/MLLab_LightGBM/lib/python3.9/site-packages/neuralforecast/common/_base_auto.py", line 209, in _train_tune
    _ = self._fit_model(
  File "/Users/ryzzhkovtom/miniconda3/envs/MLLab_LightGBM/lib/python3.9/site-packages/neuralforecast/common/_base_auto.py", line 357, in _fit_model
    model = model.fit(
  File "/Users/ryzzhkovtom/miniconda3/envs/MLLab_LightGBM/lib/python3.9/site-packages/neuralforecast/common/_base_windows.py", line 651, in fit
    return self._fit(
  File "/Users/ryzzhkovtom/miniconda3/envs/MLLab_LightGBM/lib/python3.9/site-packages/neuralforecast/common/_base_model.py", line 188, in _fit
    self._check_exog(dataset)
  File "/Users/ryzzhkovtom/miniconda3/envs/MLLab_LightGBM/lib/python3.9/site-packages/neuralforecast/common/_base_model.py", line 146, in _check_exog
    temporal_cols = set(dataset.temporal_cols.tolist())
  File "/Users/ryzzhkovtom/miniconda3/envs/MLLab_LightGBM/lib/python3.9/site-packages/pandas/core/generic.py", line 6299, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'temporal_cols'
almeidajulianojm commented 2 weeks ago

Hey @da1k-matter do you remember what was the solution? Having the same problem right now.

jmoralez commented 2 weeks ago

You need to wrap the model in a NeuralForecast instance as is done here. They don't work directly on dataframes.