{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceType":"competition","sourceId":53666,"databundleVersionId":6589269}],"dockerImageVersionId":31328,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.utils.class_weight import compute_class_weight\n\nimport tensorflow as tf\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv1D, MaxPooling1D, LSTM, Dense, Dropout\n\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-04-25T06:33:19.863229Z","iopub.execute_input":"2026-04-25T06:33:19.863487Z","iopub.status.idle":"2026-04-25T06:33:53.524068Z","shell.execute_reply.started":"2026-04-25T06:33:19.863459Z","shell.execute_reply":"2026-04-25T06:33:53.523176Z"}},"outputs":[{"name":"stderr","text":"2026-04-25 06:33:25.484648: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:467] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\nWARNING: All log messages before absl::InitializeLog() is called are written to STDERR\nE0000 00:00:1777098805.764715      55 cuda_dnn.cc:8579] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\nE0000 00:00:1777098805.839440      55 cuda_blas.cc:1407] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\nW0000 00:00:1777098806.518586      55 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\nW0000 00:00:1777098806.518625      55 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\nW0000 00:00:1777098806.518629      55 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\nW0000 00:00:1777098806.518632      55 computation_placer.cc:177] computation placer already registered. Please check linkage and avoid linking the same target more than once.\n","output_type":"stream"}],"execution_count":1},{"cell_type":"code","source":"train_series = pd.read_parquet(\"/kaggle/input/competitions/child-mind-institute-detect-sleep-states/train_series.parquet\")\ntrain_events = pd.read_csv(\"/kaggle/input/competitions/child-mind-institute-detect-sleep-states/train_events.csv\")\n\ntrain_series = train_series.sample(frac=0.3, random_state=42)\n\ntrain_series = train_series.sort_values(['series_id', 'step']).reset_index(drop=True)\ntrain_events = train_events.sort_values(['series_id', 'step'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-25T06:35:10.440603Z","iopub.execute_input":"2026-04-25T06:35:10.440931Z","iopub.status.idle":"2026-04-25T06:36:24.758025Z","shell.execute_reply.started":"2026-04-25T06:35:10.4409Z","shell.execute_reply":"2026-04-25T06:36:24.757316Z"}},"outputs":[],"execution_count":2},{"cell_type":"code","source":"train_series['enmo_roll_mean'] = train_series.groupby('series_id')['enmo'].transform(lambda x: x.rolling(10).mean())\ntrain_series['enmo_roll_std'] = train_series.groupby('series_id')['enmo'].transform(lambda x: x.rolling(10).std())\n\ntrain_series.fillna(0, inplace=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-25T06:36:40.22053Z","iopub.execute_input":"2026-04-25T06:36:40.221421Z","iopub.status.idle":"2026-04-25T06:36:57.15619Z","shell.execute_reply.started":"2026-04-25T06:36:40.22137Z","shell.execute_reply":"2026-04-25T06:36:57.155231Z"}},"outputs":[],"execution_count":3},{"cell_type":"code","source":"features = ['anglez', 'enmo', 'enmo_roll_mean', 'enmo_roll_std']\n\nscaler = StandardScaler()\ntrain_series[features] = scaler.fit_transform(train_series[features])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-25T06:37:20.453073Z","iopub.execute_input":"2026-04-25T06:37:20.453815Z","iopub.status.idle":"2026-04-25T06:37:23.671637Z","shell.execute_reply.started":"2026-04-25T06:37:20.453783Z","shell.execute_reply":"2026-04-25T06:37:23.670647Z"}},"outputs":[],"execution_count":4},{"cell_type":"code","source":"train_series['label'] = 0\n\nfor _, row in train_events.iterrows():\n    mask = (train_series['series_id'] == row['series_id']) & (train_series['step'] == row['step'])\n    \n    if row['event'] == 'onset':\n        train_series.loc[mask, 'label'] = 1\n    elif row['event'] == 'wakeup':\n        train_series.loc[mask, 'label'] = 2","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-04-25T06:37:37.385237Z","iopub.execute_input":"2026-04-25T06:37:37.385653Z"}},"outputs":[],"execution_count":null}]}