{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide\n", "!pip install -Uqq nixtla" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide \n", "from nixtla.utils import in_colab" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide \n", "IN_COLAB = in_colab()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide\n", "if not IN_COLAB:\n", " from nixtla.utils import colab_badge\n", " from dotenv import load_dotenv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Fine-tuning\n", "\n", "We can fine-tune TimeGPT by specifying the `finetune_steps` parameter." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| echo: false\n", "if not IN_COLAB:\n", " load_dotenv()\n", " colab_badge('docs/capabilities/forecast/07_finetuning')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from nixtla import NixtlaClient" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nixtla_client = NixtlaClient(\n", " # defaults to os.environ.get(\"NIXTLA_API_KEY\")\n", " api_key = 'my_api_key_provided_by_nixtla'\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> 👍 Use an Azure AI endpoint\n", "> \n", "> To use an Azure AI endpoint, remember to set also the `base_url` argument:\n", "> \n", "> `nixtla_client = NixtlaClient(base_url=\"you azure ai endpoint\", api_key=\"your api_key\")`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide\n", "if not IN_COLAB:\n", " nixtla_client = NixtlaClient()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Read data\n", "df = pd.read_csv(\"https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv\")\n", "\n", "# Forecast with fine-tuning.\n", "# Here, we fine-tune for 5 steps\n", "forecast_df = nixtla_client.forecast(\n", " df=df,\n", " h=12,\n", " finetune_steps=5,\n", " time_col='timestamp',\n", " target_col=\"value\"\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> 📘 Available models in Azure AI\n", ">\n", "> If you are using an Azure AI endpoint, please be sure to set `model=\"azureai\"`:\n", ">\n", "> `nixtla_client.forecast(..., model=\"azureai\")`\n", "> \n", "> For the public API, we support two models: `timegpt-1` and `timegpt-1-long-horizon`. \n", "> \n", "> By default, `timegpt-1` is used. Please see [this tutorial](https://docs.nixtla.io/docs/tutorials-long_horizon_forecasting) on how and when to use `timegpt-1-long-horizon`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default, only a small amount of finetuning is applied (`finetune_depth=1`). We can increase the intensity of finetuning by increasing the `finetune_depth` parameter. Note that increasing `finetune_depth` and `finetune_steps` increases wall time for generating predictions." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Read data\n", "df = pd.read_csv(\"https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/air_passengers.csv\")\n", "\n", "# Forecast with fine-tuning.\n", "# Here, we fine-tune for 5 steps\n", "# and we finetune more than just the last layer\n", "forecast_df = nixtla_client.forecast(\n", " df=df,\n", " h=12,\n", " finetune_steps=5,\n", " finetune_depth=2,\n", " time_col='timestamp',\n", " target_col=\"value\"\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For more information on fine-tuning, read our [fine-tuning tutorial](https://docs.nixtla.io/docs/tutorials-fine_tuning)." ] } ], "metadata": { "kernelspec": { "display_name": "python3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 2 }