{ "cells": [ { "cell_type": "markdown", "id": "08641fd2", "metadata": {}, "source": [ "Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n", "\n", "SPDX-License-Identifier: Apache-2.0" ] }, { "cell_type": "markdown", "id": "aee7eb47", "metadata": {}, "source": [ "# Train and Predict Wifi Data Using GDN\n", "\n", "This notebook contains the steps to\n", " 1. Find/Load the preprocess data for training using GDN \n", " 2. Train the model \n", " 3. Model inference-- Visualize the trained graph and results " ] }, { "cell_type": "markdown", "id": "4cf931c1", "metadata": {}, "source": [ "# Loading the Preprocessed Data For Training\n" ] }, { "cell_type": "code", "execution_count": null, "id": "c0624c7e", "metadata": {}, "outputs": [], "source": [ "import sys \n", "sys.path.append('../../src/anomaly_detection_spatial_temporal_data/')" ] }, { "cell_type": "code", "execution_count": null, "id": "4a9dc61b", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import yaml\n", "from model.GDN.GDNTrainer import GDNTrainer" ] }, { "cell_type": "code", "execution_count": null, "id": "81e57bfa", "metadata": {}, "outputs": [], "source": [ "data_dir = \"../../data/03_primary/wifi/gdn\"" ] }, { "cell_type": "code", "execution_count": null, "id": "95b8eced", "metadata": {}, "outputs": [], "source": [ "with open(f\"{data_dir}/wifi_sensor_list.txt\", \"r\") as f:\n", " sensors = f.read().split(\"\\n\")" ] }, { "cell_type": "code", "execution_count": null, "id": "7f4f4a44", "metadata": {}, "outputs": [], "source": [ "print(f\"Number of sensors: {len(sensors)}\")" ] }, { "cell_type": "code", "execution_count": null, "id": "b3f2b2fb", "metadata": {}, "outputs": [], "source": [ "print(sensors)" ] }, { "cell_type": "code", "execution_count": null, "id": "91f2ad9f", "metadata": {}, "outputs": [], "source": [ "train_df = pd.read_csv(f\"{data_dir}/wifi_gdn_train.csv\")\n", "test_df = pd.read_csv(f\"{data_dir}/wifi_gdn_test.csv\")\n", "\n", "print(train_df.shape)\n", "print(test_df.shape)" ] }, { "cell_type": "code", "execution_count": null, "id": "aa086b4c", "metadata": {}, "outputs": [], "source": [ "model_config_file = \"../../conf/base/parameters/gdn.yml\"" ] }, { "cell_type": "code", "execution_count": null, "id": "3cff5843", "metadata": {}, "outputs": [], "source": [ "with open(model_config_file, \"r\") as stream:\n", " try:\n", " model_config = yaml.safe_load(stream)\n", " print(model_config)\n", " except yaml.YAMLError as exc:\n", " print(exc)" ] }, { "cell_type": "code", "execution_count": null, "id": "95d3cf40", "metadata": {}, "outputs": [], "source": [ "train_config = model_config[\"train_config\"]\n", "env_config = model_config[\"env_config_wifi\"]\n", "\n", "env_config[\"checkpoint_save_dir\"] = \"../../data/07_model_output/gdn-wifi-notebook\"" ] }, { "cell_type": "markdown", "id": "c7891669", "metadata": {}, "source": [ "## Train Model" ] }, { "cell_type": "code", "execution_count": null, "id": "ca23601a", "metadata": {}, "outputs": [], "source": [ "trainer = GDNTrainer(\n", " sensors, train_df, test_df, \n", " train_config, env_config\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "e2d27450", "metadata": {}, "outputs": [], "source": [ "trainer.run()" ] }, { "cell_type": "markdown", "id": "d24db616", "metadata": {}, "source": [ "## Model Inference" ] }, { "cell_type": "code", "execution_count": null, "id": "3830eca1", "metadata": {}, "outputs": [], "source": [ "pred, labels = trainer.predict()\n" ] }, { "cell_type": "code", "execution_count": null, "id": "b106e028", "metadata": {}, "outputs": [], "source": [ "pred" ] }, { "cell_type": "code", "execution_count": null, "id": "7147954a", "metadata": {}, "outputs": [], "source": [ "pred.shape\n" ] }, { "cell_type": "code", "execution_count": null, "id": "458d9bee", "metadata": {}, "outputs": [], "source": [ "np.array(labels).shape\n" ] }, { "cell_type": "markdown", "id": "9607775f", "metadata": {}, "source": [ "# References\n", "\n", "Anisa Allahdadi and Ricardo Morla. 2017. 802.11 Wireless Access Point Usage Simulation and Anomaly Detection. CoRR abs/1707.02933, (2017). Retrieved from http://arxiv.org/abs/1707.02933 \n", "\n", "Ailin Deng and Bryan Hooi. 2021. Graph Neural Network-Based Anomaly Detection in Multivariate Time Series. CoRR abs/2106.06947, (2021). Retrieved from https://arxiv.org/abs/2106.06947 " ] }, { "cell_type": "code", "execution_count": null, "id": "2261a987", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "kedro-gdn-venv", "language": "python", "name": "kedro-gdn-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 }