Finetuning with a custom loss function
Learn how to fine-tune forecasting models using a preferred loss function for improved performance.
Finetuning with a Custom Loss Function
Fine-tuning your model allows you to specify a preferred loss function for forecasting tasks. This can significantly impact how your model learns from the data and, ultimately, its performance.
Overview
When fine-tuning, specify the loss function using the finetune_loss
argument.
The current supported values for finetune_loss
are:
mae
mse
rmse
mape
smape
Steps to Fine-Tune Your Forecast Model
1. Import Libraries
2. Initialize the Nixtla Client
By default, the NixtlaClient
will look for the API key in your environment variables (NIXTLA_API_KEY
).
By default, the NixtlaClient
will look for the API key in your environment variables (NIXTLA_API_KEY
).
To use an Azure AI endpoint, set the base_url
parameter. You can also specify the model later in the forecast
method.
3. Load Your Data
4. Fine-Tune the Model and Forecast
Using Azure AI or Nixtla’s Public API
When using an Azure AI endpoint, set model="azureai"
explicitly in the forecast
method.
When using Nixtla’s public API, two models are available:
timegpt-1
timegpt-1-long-horizon
For more details on choosing or using timegpt-1-long-horizon
, see the tutorial:
Long-Horizon Forecasting
Learn More
For a detailed explanation on how different loss functions influence model performance, read the tutorial:
Fine-tuning with a Specific Loss Function