Skip to main content
Goal: Forecast the next 7 days of daily visits to the website cienciadedatos.net using TimeGPT.
This tutorial is adapted from “Forecasting web traffic with machine learning and Python” by Joaquín Amat Rodrigo and Javier Escobar Ortiz. You will learn how to:

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.
Open In Colab
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 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
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.
Cross-validation Setup
CV Plot

Cross-validation forecast plot

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:
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.
Add Weekday Indicators
We repeat the cross-validation with these new features:
Cross-validation with Exogenous Variables
Exogenous CV Plot

Forecast with Exogenous Variables

Adding weekday indicators can capture weekly seasonality in user visits.
5

5. Comparing Results

Results

We see a slight improvement in MAE by including the weekday indicators. This illustrates how TimeGPT can incorporate additional signals without complex data processing or extensive model tuning.
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.
We have demonstrated significant improvements in forecasting accuracy with minimal effort using TimeGPT. This avoids the majority of the complex steps required when building custom models—such as extensive feature engineering, validation, model comparisons, and hyperparameter tuning.Good luck and happy forecasting!