capabilities-forecast-quickstart.mdx 3.51 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
---
title: "Forecasting Quickstart"
description: "Get started quickly with TimeGPT forecasting using the Nixtla API."
icon: "rocket"
---

[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Nixtla/nixtla/blob/main/nbs/docs/capabilities/forecast/01_quickstart.ipynb)

# Quickstart

TimeGPT makes forecasting straightforward with the `forecast` method in the Nixtla API. Pass in your DataFrame, specify the time and target columns, and call `forecast`. You can also visualize results with the `plot` method.

<Info>
  Detailed guidance on data requirements is available [here](https://docs.nixtla.io/docs/getting-started-data_requirements).
</Info>


<Steps>

<Step title="1. Install & Import Dependencies">
  Make sure you have the latest Nixtla Client installed, then import the required libraries:

```bash Nixtla Client Installation
pip install nixtla
```

```python Import Libraries
import pandas as pd
from nixtla import NixtlaClient
```
</Step>

<Step title="2. Initialize the Nixtla Client">
  <Tabs>
    <Tab title="Standard Usage">
      <Check>
        Provide your API key from Nixtla to authenticate:
      </Check>

```python Nixtla Client Standard Initialization
nixtla_client = NixtlaClient(
    # defaults to os.environ.get("NIXTLA_API_KEY")
    api_key='my_api_key_provided_by_nixtla'
)
```
    </Tab>
    <Tab title="Using Azure AI Endpoint">
      <Check>
        Use an Azure AI endpoint<br/>
        If you'd like to use Azure AI, set the `base_url` to your Azure endpoint:
      </Check>

```python Nixtla Client Azure AI Endpoint
nixtla_client = NixtlaClient(
    base_url="your azure ai endpoint",
    api_key="your api_key"
)
```
    </Tab>
  </Tabs>
</Step>

<Step title="3. Load Data & Create Forecast">

```python Load Data and Run Forecast
# Read data
df = pd.read_csv("https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv")

# Forecast for the next 12 time steps
forecast_df = nixtla_client.forecast(
    df=df,
    h=12,
    time_col='timestamp',
    target_col="value"
)
```
</Step>

<Step title="4. Visualize Predictions">

```python Plot Forecast Results
# Plot predictions
nixtla_client.plot(
    df=df,
    forecasts_df=forecast_df,
    time_col='timestamp',
    target_col='value'
)
```
</Step>

</Steps>

<Step title="Sample Logs (Optional)">
  Below is an example of log output when running a forecast:

<Accordion title="Forecast Log Output">

```bash Forecast Process Logs
INFO:nixtla.nixtla_client:Validating inputs...
INFO:nixtla.nixtla_client:Preprocessing dataframes...
INFO:nixtla.nixtla_client:Inferred freq: MS
INFO:nixtla.nixtla_client:Restricting input...
INFO:nixtla.nixtla_client:Calling Forecast Endpoint...
```

</Accordion>
</Step>

<Frame caption="TimeGPT Forecast Plot">
  ![Forecast Plot](https://raw.githubusercontent.com/Nixtla/nixtla/readme_docs/nbs/_docs/docs/capabilities/forecast/01_quickstart_files/figure-markdown_strict/cell-10-output-2.png)
</Frame>

<Info>
  **Available models in Azure AI**<br/>
  To use an Azure AI endpoint for anomaly detection, set the `model` parameter to `"azureai"`:

```python Azure AI Anomaly Detection
nixtla_client.detect_anomalies(
    ...,
    model="azureai"
)
```
</Info>

<CardGroup cols={2}>
  <Card title="timegpt-1">
    Default option for general forecasting needs.
  </Card>
  <Card title="timegpt-1-long-horizon">
    Optimized for extended forecast horizons. [Learn more here](https://docs.nixtla.io/docs/tutorials-long_horizon_forecasting).
  </Card>
</CardGroup>