Goal: Forecast the next 7 days of daily visits to the website cienciadedatos.net using TimeGPT.
Improve Accuracy
Obtain forecasts nearly 10% more accurate than the original method.
Reduce Complexity
Use significantly fewer lines of code and simpler workflows.
Save Time
Generate forecasts in substantially less computation time.
1
1. Import Packages and Initialize Client
To start, import the required packages and initialize the Nixtla client with your API key.
Nixtla Client Initialization
Use an Azure AI endpoint
If you are using an Azure AI endpoint, also set the
If you are using an Azure AI endpoint, also set the
base_url
argument:Azure AI Endpoint Setup
2
2. Load Data
We will load the website visit data directly from a CSV file. Then, we format the dataset by adding an identifier column named
daily_visits
.Load and Format Data
Data Preview (first 10 rows)
Data Preview (first 10 rows)
date | users | unique_id | |
---|---|---|---|
0 | 2020-07-01 | 2324 | daily_visits |
1 | 2020-07-02 | 2201 | daily_visits |
2 | 2020-07-03 | 2146 | daily_visits |
3 | 2020-07-04 | 1666 | daily_visits |
4 | 2020-07-05 | 1433 | daily_visits |
5 | 2020-07-06 | 2195 | daily_visits |
6 | 2020-07-07 | 2240 | daily_visits |
7 | 2020-07-08 | 2295 | daily_visits |
8 | 2020-07-09 | 2279 | daily_visits |
9 | 2020-07-10 | 2155 | daily_visits |
Note: No further preprocessing is required before we start forecasting.
3
3. Cross-Validation with TimeGPT
We will set up a rolling window cross-validation using TimeGPT. This will help us evaluate the forecast accuracy across multiple historic windows.
The results align closely with those from the original tutorial on forecasting web traffic with machine learning.Next, we compute the Mean Absolute Error (MAE) to quantify forecast accuracy:
Cross-validation Setup

Cross-validation forecast plot
Calculate MAE
MAE Result: The MAE obtained is
167.69
, outperforming the original pipeline.4
4. Adding Exogenous Variables (Weekday Indicators)
Exogenous variables can provide additional context that may improve forecast accuracy. In this example, we add binary indicators for each day of the week.We repeat the cross-validation with these new features:
Add Weekday Indicators
Cross-validation with Exogenous Variables

Forecast with Exogenous Variables
Adding weekday indicators can capture weekly seasonality in user visits.
5
5. Comparing Results
Results
Model | Exogenous features | MAE Backtest |
---|---|---|
TimeGPT | No | 167.6917 |
TimeGPT | Yes | 167.2286 |
6
6. Final Thoughts
Key Takeaways
- TimeGPT simplifies forecasting workflows by reducing code and tuning overhead.
- Feature engineering (like adding weekday variables) further boosts accuracy.
- Cross-validation provides a robust way to evaluate model performance.