capabilities-forecast-fine_tuning.mdx 4.09 KB
Newer Older
bailuo's avatar
readme  
bailuo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
---
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.

<Info>
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.
</Info>

---

## Key Fine-tuning Concepts

<CardGroup>
  <Card title="finetune_steps" icon="gear">
    The number of additional training steps to run. Increasing this value can improve accuracy, but also requires more computation.
  </Card>
  <Card title="finetune_depth" icon="circle-up">
    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.
  </Card>
</CardGroup>

<Warning>
If you set both `finetune_steps` and `finetune_depth` too high, the training process can become very time-consuming.
</Warning>

---

## Setting Up Your Environment

Before creating forecasts, you need to install and initialize the Nixtla client with your API key.

<Steps>
  <Steps title="Install and Import Libraries">
    ```python Import Libraries
    import pandas as pd
    from nixtla import NixtlaClient
    ```
  </Steps>
  <Steps title="Initialize the Nixtla Client">
    ```python Initialize Nixtla Client
    nixtla_client = NixtlaClient(
        # defaults to os.environ.get("NIXTLA_API_KEY")
        api_key="my_api_key_provided_by_nixtla"
    )
    ```
  </Steps>
</Steps>

<Info>
If you're using an Azure AI endpoint, set the `base_url` parameter accordingly:
</Info>

```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.

<Steps>
  <Steps title="Load Data">
    ```python Load Dataset
    df = pd.read_csv(
        "https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv"
    )
    ```
  </Steps>
  <Steps title="Create a Forecast (Example: 5 Fine-tune Steps)">
    ```python Fine-tune Forecast Example
    forecast_df = nixtla_client.forecast(
        df=df,
        h=12,
        finetune_steps=5,
        time_col="timestamp",
        target_col="value"
    )
    ```
  </Steps>
</Steps>

<Check>
If you are using Azure AI, specify the model name explicitly:
</Check>

<CodeGroup>
  ```python Azure AI Model Usage
  nixtla_client.forecast(
      df=df,
      h=12,
      finetune_steps=5,
      model="azureai",
      time_col="timestamp",
      target_col="value"
  )
  ```
</CodeGroup>

<Info>
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`.
</Info>

---

## Advanced Fine-tuning

<AccordionGroup>
  <Accordion title="Increase Fine-tuning Depth">
    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"
    )
    ```
  </Accordion>
</AccordionGroup>

<Info>
Increasing `finetune_depth` and `finetune_steps` will increase computation time, thus requiring more time to generate predictions.
</Info>

---

## Additional Resources

For more detailed information and advanced configurations, see the
[fine-tuning tutorial](https://docs.nixtla.io/docs/tutorials-fine_tuning).