Skip to content

Commit

Permalink
change column names
Browse files Browse the repository at this point in the history
  • Loading branch information
Yibei990826 committed Nov 27, 2024
1 parent a0f3dfa commit e3fa7ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 57 deletions.
54 changes: 6 additions & 48 deletions nbs/src/nixtla_client.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"#| hide\n",
"load_dotenv(override=True)"
Expand Down Expand Up @@ -1815,10 +1804,9 @@
" }\n",
" )\n",
" out = ufp.assign_columns(out, 'TimeGPT', resp['mean'])\n",
" out_aggregated = (out.groupby(['unique_id', 'ds'])\n",
" .agg({'TimeGPT': 'median', 'y': 'first'})\n",
" .reset_index())\n",
" out = (out_aggregated.groupby('unique_id')\n",
" out_aggregated = (out.groupby([id_col, time_col], as_index=False)\n",
" .agg({'TimeGPT': 'median', target_col: 'first'}))\n",
" out = (out_aggregated.groupby(id_col)\n",
" .tail(detection_size)\n",
" .reset_index(drop=True))\n",
" out = ufp.assign_columns(out, 'anomaly', resp['anomaly'])\n",
Expand Down Expand Up @@ -2549,18 +2537,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"#| hide\n",
"nixtla_client.validate_api_key()"
Expand Down Expand Up @@ -3544,26 +3521,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:__main__:Validating inputs...\n",
"INFO:__main__:Preprocessing dataframes...\n",
"INFO:__main__:Calling Online Anomaly Detector Endpoint...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:__main__:Validating inputs...\n",
"INFO:__main__:Preprocessing dataframes...\n",
"INFO:__main__:Calling Online Anomaly Detector Endpoint...\n"
]
}
],
"outputs": [],
"source": [
"#| hide\n",
"# Test real-time anomaly detection\n",
Expand Down
12 changes: 3 additions & 9 deletions nixtla/nixtla_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1746,16 +1746,10 @@ def detect_anomalies_realtime(
}
)
out = ufp.assign_columns(out, "TimeGPT", resp["mean"])
out_aggregated = (
out.groupby(["unique_id", "ds"])
.agg({"TimeGPT": "median", "y": "first"})
.reset_index()
)
out = (
out_aggregated.groupby("unique_id")
.tail(detection_size)
.reset_index(drop=True)
out_aggregated = out.groupby([id_col, time_col], as_index=False).agg(
{"TimeGPT": "median", target_col: "first"}
)
out = out_aggregated.groupby(id_col).tail(detection_size).reset_index(drop=True)
out = ufp.assign_columns(out, "anomaly", resp["anomaly"])
out = ufp.assign_columns(out, "anomaly_score", resp["anomaly_score"])
return _maybe_add_intervals(out, resp["intervals"])
Expand Down

0 comments on commit e3fa7ce

Please sign in to comment.