unit8co / darts

A python library for user-friendly forecasting and anomaly detection on time series.
https://unit8co.github.io/darts/
Apache License 2.0
7.92k stars 860 forks source link

[BUG] .backtest method is not working #1516

Closed mrsergazinov closed 1 year ago

mrsergazinov commented 1 year ago

Describe the bug Type mismatch in the .backtest method due to a typo in the for-loop.

To Reproduce The bug is general for any model that uses the .backtest method. For simplicity, I pick ARIMA.

import sys
import os
import yaml
sys.path.insert(1, '..')
os.chdir('..')

import seaborn as sns
sns.set_style('whitegrid')
import matplotlib.pyplot as plt
import statsmodels.api as sm
import sklearn
import optuna

from darts import models
from darts import metrics
from darts import TimeSeries
from darts.dataprocessing.transformers import Scaler
from darts.datasets import AirPassengersDataset, MonthlyMilkDataset

# load datasets
air_passengers = AirPassengersDataset().load()
milk = MonthlyMilkDataset().load()

# create sequence of series
series = [air_passengers, milk]

# define model
arima = models.ARIMA(p=1, d=1, q=1, seasonal_order=(0, 0, 0, 0))

# backtest
error = arima.backtest(series,
                                        train_length=30,
                                        forecast_horizon=2,
                                        stride=1,
                                        retrain=True,
                                        last_points_only=False,
                                        verbose=False)

Expected behavior The .backtest should produce the errors.

System (please complete the following information):

Additional context This is simple to fix by replacing series with target_ts in the forecasting_model.py file.

hrzn commented 1 year ago

Thanks for reporting @mrsergazinov That's indeed a bug, and should be fixed by https://github.com/unit8co/darts/pull/1517