Fine-tuning with a Specific Loss Function
Learn how to fine-tune a model using specific loss functions, configure the Nixtla client, and evaluate performance improvements.
This tutorial shows how to fine-tune a model using a specific loss function. You will learn which loss functions are supported, how to configure your Nixtla client, and how to evaluate different approaches for best results.
When you fine-tune, the model trains on your dataset to tailor predictions to your specific scenario. You can specify the loss function to be used during fine-tuning. Below are the available loss functions:
Default
A proprietary function robust to outliers.
MAE
Mean Absolute Error
MSE
Mean Squared Error
RMSE
Root Mean Squared Error
MAPE
Mean Absolute Percentage Error
sMAPE
Symmetric Mean Absolute Percentage Error
1. Import Packages
Make sure you have the necessary dependencies installed (such as pandas
and nixtla
).
Initialize the NixtlaClient object
Replace api_key='my_api_key_provided_by_nixtla'
with the API key from your Nixtla account.
Using an Azure AI endpoint
Pass the base_url
argument explicitly:
2. Load Data
Load your data and prepare it for fine-tuning. Here, we will demonstrate using an example dataset of air passenger counts.
unique_id | timestamp | value | |
---|---|---|---|
0 | 1 | 1949-01-01 | 112 |
1 | 1 | 1949-02-01 | 118 |
2 | 1 | 1949-03-01 | 132 |
3 | 1 | 1949-04-01 | 129 |
4 | 1 | 1949-05-01 | 121 |
3. Fine-Tune the Model
For other fine-tuning configurations, simply change finetune_loss
to your preferred loss function (mse, rmse, mape, or smape).
Selecting the appropriate loss function during fine-tuning ensures the model is optimized around what matters most for your use case.
Perform a quick evaluation to compare metrics across different loss functions. Fine-tuning with a specific loss can yield better accuracy for your goals.
mae | mse | rmse | mape | smape | |
---|---|---|---|---|---|
Metric improvement (%) | 8.54 | 0.31 | 0.64 | 31.02 | 7.36 |
By aligning the model’s training objective with your key evaluation metric, you achieve more targeted performance improvements for your forecasting tasks.