Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOC] - Reduce code blocks in capabilties #339

Merged
merged 11 commits into from
May 10, 2024
76 changes: 24 additions & 52 deletions nbs/docs/capabilities/anomaly-detection/01_quickstart.ipynb

Large diffs are not rendered by default.

81 changes: 19 additions & 62 deletions nbs/docs/capabilities/anomaly-detection/02_anomaly_exogenous.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 1: Create an instance of `NixtlaClient`"
"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 +20,7 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from nixtla import NixtlaClient"
]
},
Expand Down Expand Up @@ -56,40 +57,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 +72,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 +95,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 @@ -11,7 +11,7 @@
"cell_type": "markdown",
marcopeix marked this conversation as resolved.
Show resolved Hide resolved
"metadata": {},
"source": [
"## Step 1: Create an instance of `NixtlaClient`"
"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 st it to `True` to extract all possible features, or pass a list of features we want to include."
]
},
{
Expand All @@ -20,6 +20,7 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from nixtla import NixtlaClient"
]
},
Expand Down Expand Up @@ -56,43 +57,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 +71,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 +94,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
95 changes: 29 additions & 66 deletions nbs/docs/capabilities/anomaly-detection/04_confidence_levels.ipynb

Large diffs are not rendered by default.

74 changes: 17 additions & 57 deletions nbs/docs/capabilities/forecast/01_quickstart.ipynb

Large diffs are not rendered by default.

72 changes: 22 additions & 50 deletions nbs/docs/capabilities/forecast/02_exogenous_variables.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 1: Create an instance of `NixtlaClient`"
"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 +20,7 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from nixtla import NixtlaClient"
]
},
Expand Down Expand Up @@ -56,54 +57,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 +75,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
Loading
Loading