TimeCopilot Forecasterยถ
Import librariesยถ
Inย [2]:
Copied!
import pandas as pd
from timecopilot import TimeCopilotForecaster
import pandas as pd
from timecopilot import TimeCopilotForecaster
Load the dataset.ยถ
The DataFrame must include at least the following columns:
- unique_id: Unique identifier for each time series (string)
- ds: Date column (datetime format)
- y: Target variable for forecasting (float format)
The pandas frequency will be inferred from the ds column, if not provided. If the seasonality is not provided, it will be inferred based on the frequency. If the horizon is not set, it will default to 2 times the inferred seasonality.
Inย [3]:
Copied!
df = pd.read_csv(
"https://timecopilot.s3.amazonaws.com/public/data/air_passengers.csv",
parse_dates=["ds"],
)
df.head()
df = pd.read_csv(
"https://timecopilot.s3.amazonaws.com/public/data/air_passengers.csv",
parse_dates=["ds"],
)
df.head()
Out[3]:
unique_id | ds | y | |
---|---|---|---|
0 | AirPassengers | 1949-01-01 | 112 |
1 | AirPassengers | 1949-02-01 | 118 |
2 | AirPassengers | 1949-03-01 | 132 |
3 | AirPassengers | 1949-04-01 | 129 |
4 | AirPassengers | 1949-05-01 | 121 |
Import the models you want to useยถ
Inย [9]:
Copied!
from timecopilot.models.benchmarks.prophet import Prophet
from timecopilot.models.benchmarks.stats import AutoARIMA, AutoETS, SeasonalNaive
from timecopilot.models.foundational.moirai import Moirai
from timecopilot.models.benchmarks.prophet import Prophet
from timecopilot.models.benchmarks.stats import AutoARIMA, AutoETS, SeasonalNaive
from timecopilot.models.foundational.moirai import Moirai
Create a TimeCopilotForecasterยถ
Inย [10]:
Copied!
tcf = TimeCopilotForecaster(
models=[
AutoARIMA(),
AutoETS(),
Moirai(),
Prophet(),
SeasonalNaive(),
]
)
tcf = TimeCopilotForecaster(
models=[
AutoARIMA(),
AutoETS(),
Moirai(),
Prophet(),
SeasonalNaive(),
]
)
Generate forecastยถ
You can optionally specify the following parameters:
- freq: The frequency of your data (e.g., 'D' for daily, 'M' for monthly)
- h: The forecast horizon, which is the number of periods to predict
- seasonality: The seasonal period of your data, which can be inferred if not provided
Inย [ย ]:
Copied!
fcst_df = tcf.forecast(df=df, h=12, level=[80, 90])
fcst_df = tcf.forecast(df=df, h=12, level=[80, 90])
1it [00:00, 1.96it/s] 11:34:12 - cmdstanpy - INFO - Chain [1] start processing 11:34:12 - cmdstanpy - INFO - Chain [1] done processing
Plot resultsยถ
Inย [14]:
Copied!
tcf.plot(df, fcst_df, level=[80, 90])
tcf.plot(df, fcst_df, level=[80, 90])
Out[14]: