---
title: "Fine-tuning"
description: "How to fine-tune TimeGPT forecasts using finetune_steps and finetune_depth parameters for improved accuracy."
icon: "gear"
---
## Overview
You can fine-tune TimeGPT forecasts by specifying the `finetune_steps` parameter. Fine-tuning allows you to further adjust the model to the nuances of your specific time series data, potentially improving forecast accuracy.
Fine-tuning uses additional training iterations on your own dataset. While it can improve forecast performance, it also increases the compute time needed to generate predictions.
---
## Key Fine-tuning Concepts
The number of additional training steps to run. Increasing this value can improve accuracy, but also requires more computation.
The intensity or depth of the fine-tuning. By default, `finetune_depth=1`. Increasing it can further refine forecasts but also makes training more resource-intensive.
If you set both `finetune_steps` and `finetune_depth` too high, the training process can become very time-consuming.
---
## Setting Up Your Environment
Before creating forecasts, you need to install and initialize the Nixtla client with your API key.
```python Import Libraries
import pandas as pd
from nixtla import NixtlaClient
```
```python Initialize Nixtla Client
nixtla_client = NixtlaClient(
# defaults to os.environ.get("NIXTLA_API_KEY")
api_key="my_api_key_provided_by_nixtla"
)
```
If you're using an Azure AI endpoint, set the `base_url` parameter accordingly:
```python Azure AI Configuration
nixtla_client = NixtlaClient(
base_url="your azure ai endpoint",
api_key="your api_key"
)
```
---
## Forecasting with Fine-tuning
Follow these steps to fine-tune your TimeGPT forecasts.
```python Load Dataset
df = pd.read_csv(
"https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv"
)
```
```python Fine-tune Forecast Example
forecast_df = nixtla_client.forecast(
df=df,
h=12,
finetune_steps=5,
time_col="timestamp",
target_col="value"
)
```
If you are using Azure AI, specify the model name explicitly:
```python Azure AI Model Usage
nixtla_client.forecast(
df=df,
h=12,
finetune_steps=5,
model="azureai",
time_col="timestamp",
target_col="value"
)
```
In the public Nixtla API, you can choose from two models:
- `timegpt-1` (default)
- `timegpt-1-long-horizon`
See the [long-horizon forecasting tutorial](https://docs.nixtla.io/docs/tutorials-long_horizon_forecasting) for information about when and how to use `timegpt-1-long-horizon`.
---
## Advanced Fine-tuning
By default, `finetune_depth=1`. You can increase the fine-tuning intensity by specifying a higher `finetune_depth`.
```python Increase Fine-tuning Depth Example
df = pd.read_csv(
"https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv"
)
forecast_df = nixtla_client.forecast(
df=df,
h=12,
finetune_steps=5,
finetune_depth=2,
time_col="timestamp",
target_col="value"
)
```
Increasing `finetune_depth` and `finetune_steps` will increase computation time, thus requiring more time to generate predictions.
---
## Additional Resources
For more detailed information and advanced configurations, see the
[fine-tuning tutorial](https://docs.nixtla.io/docs/tutorials-fine_tuning).