Skip to content

Commit

Permalink
docs: reduce code blocks in capabilties (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopeix committed May 10, 2024
1 parent ad6551f commit e9d01e6
Show file tree
Hide file tree
Showing 18 changed files with 901 additions and 843 deletions.
85 changes: 26 additions & 59 deletions nbs/docs/capabilities/anomaly-detection/01_quickstart.ipynb

Large diffs are not rendered by default.

90 changes: 21 additions & 69 deletions nbs/docs/capabilities/anomaly-detection/02_anomaly_exogenous.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Add exogenous variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 1: Create an instance of `NixtlaClient`"
"# Add exogenous variables\n",
"\n",
"Anomaly detection with exogenous variables simply requires to load a dataset with the exogenous features as columns. We use the same `detect_anomalies` method and we can also plot the weights of each feature using `weight_x.plot()`."
]
},
{
Expand All @@ -20,6 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from nixtla import NixtlaClient"
]
},
Expand Down Expand Up @@ -56,40 +52,6 @@
"nixtla_client = NixtlaClient()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 2: Load your dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/electricity-short-with-ex-vars.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 3: Anomaly detection with exogenous variables\n",
"\n",
"Simple include exogenous features in your dataset and TimeGPT will consider them for anomaly detection."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -105,29 +67,7 @@
"INFO:nixtla.nixtla_client:Calling Anomaly Detector Endpoint...\n",
"INFO:nixtla.nixtla_client:Using the following exogenous variables: Exogenous1, Exogenous2, day_0, day_1, day_2, day_3, day_4, day_5, day_6\n"
]
}
],
"source": [
"anomalies_df = nixtla_client.detect_anomalies(\n",
" df=df,\n",
" time_col='ds',\n",
" target_col='y'\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 4: Plot weights of features\n",
"It is then possible to plot the importance of each feature."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
},
{
"data": {
"text/plain": [
Expand All @@ -150,15 +90,27 @@
}
],
"source": [
"# Read the dataset\n",
"# The dataset has exogenous features in its columns\n",
"df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/electricity-short-with-ex-vars.csv')\n",
"\n",
"# Detect anomalies\n",
"anomalies_df = nixtla_client.detect_anomalies(\n",
" df=df,\n",
" time_col='ds',\n",
" target_col='y'\n",
")\n",
"\n",
"# Plot weight of exgeonous features\n",
"nixtla_client.weights_x.plot.barh(x='features', y='weights')"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
"source": [
"Read our detailed guide on [anomaly detection](https://docs.nixtla.io/docs/tutorials/anomaly_detection) for more information."
]
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Add date features"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 1: Create an instance of `NixtlaClient`"
"# Add date features\n",
"\n",
"If your dataset does not have exogenous variables, you can add date features to inform the model for anomaly detection. This is done using the `date_features` argument. We can set it to `True` to extract all possible features, or pass a list of features we want to include."
]
},
{
Expand All @@ -20,6 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from nixtla import NixtlaClient"
]
},
Expand Down Expand Up @@ -56,43 +52,6 @@
"nixtla_client = NixtlaClient()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 2: Load your dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/peyton_manning.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 3: Anomaly detection with date features.\n",
"You can automatically add date features for anomaly detection using the `date_features` parameter. \n",
"\n",
"Setting `date_features` to `True` extract all the possible date features from the dataset. \n",
"\n",
"You can also pass a list of date features you want to create, like `['days', 'month']`."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -107,31 +66,7 @@
"INFO:nixtla.nixtla_client:Calling Anomaly Detector Endpoint...\n",
"INFO:nixtla.nixtla_client:Using the following exogenous variables: month_1, month_2, month_3, month_4, month_5, month_6, month_7, month_8, month_9, month_10, month_11, month_12, year_2007, year_2008, year_2009, year_2010, year_2011, year_2012, year_2013, year_2014, year_2015, year_2016\n"
]
}
],
"source": [
"anomalies_df_x = nixtla_client.detect_anomalies(\n",
" df, time_col='timestamp', \n",
" target_col='value', \n",
" freq='D', \n",
" date_features=['month', 'year'],\n",
" level=99.99,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 4: Plot weights of features\n",
"It is then possible to plot the importance of each feature."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
},
{
"data": {
"text/plain": [
Expand All @@ -154,14 +89,33 @@
}
],
"source": [
"# Read the data\n",
"df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/peyton_manning.csv')\n",
"\n",
"# Add date features for anomaly detection\n",
"# Here, we use date features at the month and year levels\n",
"anomalies_df_x = nixtla_client.detect_anomalies(\n",
" df, time_col='timestamp', \n",
" target_col='value', \n",
" freq='D', \n",
" date_features=['month', 'year'],\n",
" level=99.99,\n",
")\n",
"\n",
"# Plot weights of date features\n",
"nixtla_client.weights_x.plot.barh(x='features', y='weights')"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"source": [
"For more details, check out our in-depth tutorial on [anomaly detection](https://docs.nixtla.io/docs/tutorials/anomaly_detection)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
}
],
Expand Down
104 changes: 31 additions & 73 deletions nbs/docs/capabilities/anomaly-detection/04_confidence_levels.ipynb

Large diffs are not rendered by default.

83 changes: 19 additions & 64 deletions nbs/docs/capabilities/forecast/01_quickstart.ipynb

Large diffs are not rendered by default.

81 changes: 24 additions & 57 deletions nbs/docs/capabilities/forecast/02_exogenous_variables.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Add exogenous variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 1: Create an instance of `NixtlaClient`"
"# Add exogenous variables\n",
"\n",
"To model with exogenous features, simply include them in the DataFrame that you pass as input to the `forecast` method. Note that you need to provide the future values of those exogenous features over the forecast horizon using the `X_df` parameter."
]
},
{
Expand All @@ -20,6 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from nixtla import NixtlaClient"
]
},
Expand Down Expand Up @@ -56,54 +52,6 @@
"nixtla_client = NixtlaClient()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 2: Load data with exogenous variables"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/electricity-short-with-ex-vars.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 3: Load dataset with future values of exogenous variables"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"future_ex_vars_df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/electricity-short-future-ex-vars.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 4: Forecast"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -122,15 +70,34 @@
}
],
"source": [
"# Read data\n",
"df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/electricity-short-with-ex-vars.csv')\n",
"\n",
"# Load the future value of exogenous variables over the forecast horizon\n",
"future_ex_vars_df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/electricity-short-future-ex-vars.csv')\n",
"\n",
"# Forecast\n",
"forecast_df = nixtla_client.forecast(\n",
" df=df, \n",
" X_df=future_ex_vars_df, \n",
" h=24,\n",
" id_col='unique_id',\n",
" target_col='y',\n",
" time_col='ds'\n",
")"
")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For more details on using exogenous features with TimeGPT, read our in-depth tutorials on [Exogenous variables](https://docs.nixtla.io/docs/tutorials-exogenous_variables) and on [Categorical variables](https://docs.nixtla.io/docs/tutorials-categorical_variables)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit e9d01e6

Please sign in to comment.