{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":93783,"databundleVersionId":11331308,"sourceType":"competition"}],"dockerImageVersionId":30918,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-03-12T16:27:35.695713Z","iopub.execute_input":"2025-03-12T16:27:35.696162Z","iopub.status.idle":"2025-03-12T16:27:37.134065Z","shell.execute_reply.started":"2025-03-12T16:27:35.696122Z","shell.execute_reply":"2025-03-12T16:27:37.132805Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Load all channels and show stats\ntrain_df = pd.read_parquet(\"/kaggle/input/esa-adb-challenge/train.parquet\")\nchannel_names = [x for x in train_df.columns if x not in [\"id\", \"is_anomaly\"]]\ntrain_df[channel_names].describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T16:27:37.135745Z","iopub.execute_input":"2025-03-12T16:27:37.136338Z","iopub.status.idle":"2025-03-12T16:28:32.807864Z","shell.execute_reply.started":"2025-03-12T16:27:37.136306Z","shell.execute_reply":"2025-03-12T16:28:32.806412Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Limit to channels 41-52\nchannel_names = [f\"channel_{x}\" for x in range(41,52 + 1)]\ntrain_df[channel_names].describe()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T16:44:04.185806Z","iopub.execute_input":"2025-03-12T16:44:04.186458Z","iopub.status.idle":"2025-03-12T16:44:11.033117Z","shell.execute_reply.started":"2025-03-12T16:44:04.186418Z","shell.execute_reply":"2025-03-12T16:44:11.031864Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Visualization of an example anomaly from the training set\nfrom matplotlib import pyplot as plt\nfrom matplotlib.patches import Rectangle\nplt.rcParams[\"image.cmap\"] = \"Set2\"\nplt.rcParams['axes.prop_cycle'] = plt.cycler(color=plt.cm.Set2.colors)\nplt.figure(figsize=(10,7))\n\nstart_idx = 606062\nend_idx = start_idx + 10000\n\nplt.step(train_df.loc[start_idx:end_idx, \"id\"], train_df.loc[start_idx:end_idx, \"is_anomaly\"] + 1, alpha=0.8, label=\"is_anomaly\", where=\"post\", color=\"red\")\n\nfor i, channel in enumerate(channel_names):\n    d = train_df.loc[start_idx:end_idx, channel]\n    d = (d - np.min(d))/(np.max(d) - np.min(d))\n\n    plt.step(train_df.loc[start_idx:end_idx, \"id\"], d - i, alpha=0.8, label=channel, where=\"post\")\n\nplt.xlabel(\"Time point id\")\nplt.yticks([], [])\nplt.legend(loc=\"upper right\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-12T16:50:27.401901Z","iopub.execute_input":"2025-03-12T16:50:27.402375Z","iopub.status.idle":"2025-03-12T16:50:28.081026Z","shell.execute_reply.started":"2025-03-12T16:50:27.402313Z","shell.execute_reply":"2025-03-12T16:50:28.079683Z"}},"outputs":[],"execution_count":null}]}