{ "cells": [ { "cell_type": "markdown", "id": "9362a795", "metadata": {}, "source": [ "Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n", "\n", "SPDX-License-Identifier: Apache-2.0" ] }, { "cell_type": "markdown", "id": "7af6134f", "metadata": {}, "source": [ "## Table of Contents\n", "\n", "1. Specify data folder containing individual CSVs\n", "2. Specify location containing label JSON\n", "3. Train Context OSE Model from NAB library\n", "4. Perform inference on test set" ] }, { "cell_type": "code", "execution_count": null, "id": "5c33aa64", "metadata": {}, "outputs": [], "source": [ "import sys\n", "sys.path.append(\"../../src/\")" ] }, { "cell_type": "code", "execution_count": null, "id": "efe6b81d", "metadata": {}, "outputs": [], "source": [ "from anomaly_detection_spatial_temporal_data.model.time_series import NABAnomalyDetector" ] }, { "cell_type": "code", "execution_count": null, "id": "1a568e2d", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "markdown", "id": "7bc78bbe", "metadata": {}, "source": [ "# Train NAB Context OSE model" ] }, { "cell_type": "code", "execution_count": null, "id": "2804bfe5", "metadata": {}, "outputs": [], "source": [ "model_name = \"contextOSE\"\n", "model_path = \"../../src/anomaly_detection_spatial_temporal_data/model/NAB\"\n", "input_dir = \"../../data/02_intermediate/iot/ts_data\"\n", "label_file = \"../../data/02_intermediate/iot/ts_label/labels-test.json\"\n", "output_dir = \"../../data/07_model_output/iot/ts_result-notebook\"" ] }, { "cell_type": "code", "execution_count": null, "id": "503574f4", "metadata": {}, "outputs": [], "source": [ "nab = NABAnomalyDetector(\n", " model_name, \n", " model_path,\n", " input_dir,\n", " label_file,\n", " output_dir,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "0ccbfa94", "metadata": {}, "outputs": [], "source": [ "nab.predict()" ] }, { "cell_type": "markdown", "id": "06df5434", "metadata": {}, "source": [ "# Load an inference result\n", "The NAB time series anomaly models use the historical context in a specific time series to identify if a future time step is an anomaly. Each time series is treated independently, so we do not expect this model to perform well on this dataset." ] }, { "cell_type": "code", "execution_count": null, "id": "637856ff", "metadata": {}, "outputs": [], "source": [ "!ls ../../data/07_model_output/iot/ts_result-notebook/contextOSE/" ] }, { "cell_type": "code", "execution_count": null, "id": "691df064", "metadata": { "scrolled": true }, "outputs": [], "source": [ "output_csv = \"contextOSE_L_T1.csv\"\n", "\n", "df_out = pd.read_csv(f\"{output_dir}/contextOSE/{output_csv}\")" ] }, { "cell_type": "code", "execution_count": null, "id": "3779049e", "metadata": {}, "outputs": [], "source": [ "df_out.head(20)" ] }, { "cell_type": "markdown", "id": "98e040de", "metadata": {}, "source": [ "# References\n", "Riccardo Taormina and Stefano Galelli and Nils Ole Tippenhauer and Elad Salomons and Avi Ostfeld and Demetrios G. Eliades and Mohsen Aghashahi and Raanju Sundararajan and Mohsen Pourahmadi and M. Katherine Banks and B. M. Brentan and Enrique Campbell and G. Lima and D. Manzi and D. Ayala-Cabrera and M. Herrera and I. Montalvo and J. Izquierdo and E. Luvizotto and Sarin E. Chandy and Amin Rasekh and Zachary A. Barker and Bruce Campbell and M. Ehsan Shafiee and Marcio Giacomoni and Nikolaos Gatsis and Ahmad Taha and Ahmed A. Abokifa and Kelsey Haddad and Cynthia S. Lo and Pratim Biswas and M. Fayzul K. Pasha and Bijay Kc and Saravanakumar Lakshmanan Somasundaram and Mashor Housh and Ziv Ohar; \"The Battle Of The Attack Detection Algorithms: Disclosing Cyber Attacks On Water Distribution Networks.\" Journal of Water Resources Planning and Management, 144 (8), August 2018\n", "\n", "Alexander Lavin and Subutai Ahmad. 2015. Evaluating Real-Time Anomaly Detection Algorithms – The Numenta Anomaly Benchmark." ] }, { "cell_type": "code", "execution_count": null, "id": "04e53d55", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "kedro-nab-venv", "language": "python", "name": "kedro-nab-venv" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.12" } }, "nbformat": 4, "nbformat_minor": 5 }