You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can't reproduce the issue from this piece of code - from the error it seems that there is something in your input data that is not of the correct datatype.
Could you provide a fully, standalone, piece of code so I can reproduce?
I can't reproduce the issue from this piece of code - from the error it seems that there is something in your input data that is not of the correct datatype.
Could you provide a fully, standalone, piece of code so I can reproduce?
The issue has been resolved. It was because my dates were in string format.
What happened + What you expected to happen
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /Users/leo/web3/LLM/langchain/mlts/test.py:30 in │
│ │
│ 27 nf = NeuralForecast(models=models, freq="D") │
│ 28 │
│ 29 nf.fit(df=Y_train_df) │
│ ❱ 30 Y_hat_df = nf.predict().reset_index() │
│ 31 │
│ 32 # Plot predictions │
│ 33 fig, ax = plt.subplots(1, 1, figsize=(20, 7)) │
│ │
│ /Users/leo/web3/LLM/langchain/venv/lib/python3.10/site-packages/neuralforecast/core.py:304 in │
│ predict │
│ │
│ 301 │ │ │ cols += [model_name + n for n in model.loss.output_names] │
│ 302 │ │ │
│ 303 │ │ # Placeholder dataframe for predictions with unique_id and ds │
│ ❱ 304 │ │ fcsts_df = _future_dates( │
│ 305 │ │ │ dataset=dataset, uids=uids, last_dates=last_dates, freq=self.freq, h=self.h │
│ 306 │ │ ) │
│ 307 │
│ │
│ /Users/leo/web3/LLM/langchain/venv/lib/python3.10/site-packages/neuralforecast/core.py:107 in │
│ _future_dates │
│ │
│ 104 │ else: │
│ 105 │ │ last_date_f = lambda x: pd.date_range(x + freq, periods=h, freq=freq) │
│ 106 │ if len(np.unique(last_dates)) == 1: │
│ ❱ 107 │ │ dates = np.tile(last_date_f(last_dates[0]), len(dataset)) │
│ 108 │ else: │
│ 109 │ │ dates = np.hstack([last_date_f(last_date) for last_date in last_dates]) │
│ 110 │ idx = pd.Index(np.repeat(uids, h), name="unique_id") │
│ │
│ /Users/leo/web3/LLM/langchain/venv/lib/python3.10/site-packages/neuralforecast/core.py:105 in │
│ │
│ │
│ 102 │ if issubclass(last_dates.dtype.type, np.integer): │
│ 103 │ │ last_date_f = lambda x: np.arange(x + 1, x + 1 + h, dtype=last_dates.dtype) │
│ 104 │ else: │
│ ❱ 105 │ │ last_date_f = lambda x: pd.date_range(x + freq, periods=h, freq=freq) │
│ 106 │ if len(np.unique(last_dates)) == 1: │
│ 107 │ │ dates = np.tile(last_date_f(last_dates[0]), len(dataset)) │
│ 108 │ else: │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: can only concatenate str (not "pandas._libs.tslibs.offsets.Day") to str
Versions / Dependencies
Name: neuralforecast
Version: 1.5.0
Summary: Time series forecasting suite using deep learning models
Home-page: https://github.com/Nixtla/neuralforecast/
Author: Nixtla
Author-email: business@nixtla.io
License: Apache Software License 2.0
Location: /Users/leo/web3/LLM/langchain/venv/lib/python3.10/site-packages
Requires: numpy, pandas, pytorch-lightning, ray, torch
Required-by:
Reproduction script
Split data and declare panel datasee
Y_train_df = Y_df[Y_df.ds <= '2024-04-03'] # 132 train
Y_test_df = Y_df[(Y_df.ds > '2024-04-03') & (Y_df.ds < '2024-04-15')] # 12 test
Fit and predict with NBEATS and NHITS models
horizon = len(Y_test_df)
models = [NBEATS(input_size=2 * horizon, h=horizon, max_steps=1),
NHITS(input_size=2 * horizon, h=horizon, max_steps=1)]
nf = NeuralForecast(models=models, freq="D")
nf.fit(df=Y_train_df)
Y_hat_df = nf.predict().reset_index()
Plot predictions
fig, ax = plt.subplots(1, 1, figsize=(20, 7))
Y_hat_df = Y_test_df.merge(Y_hat_df, how='left', on=['unique_id', 'ds'])
plot_df = pd.concat([Y_train_df, Y_hat_df]).set_index('ds')
plot_df[['y', 'NBEATS', 'NHITS']].plot(ax=ax, linewidth=2)
ax.set_title('AirPassengers Forecast', fontsize=22)
ax.set_ylabel('Monthly Passengers', fontsize=20)
ax.set_xlabel('Timestamp [t]', fontsize=20)
ax.legend(prop={'size': 15})
ax.grid()
plt.show()
Issue Severity
None
The text was updated successfully, but these errors were encountered: