{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":59093,"databundleVersionId":7469972,"sourceType":"competition"}],"dockerImageVersionId":30646,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport torch\nimport os","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:07.241461Z","iopub.execute_input":"2024-03-03T22:07:07.241960Z","iopub.status.idle":"2024-03-03T22:07:13.022601Z","shell.execute_reply.started":"2024-03-03T22:07:07.241900Z","shell.execute_reply":"2024-03-03T22:07:13.020644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df_org = pd.read_csv(\"/kaggle/input/hms-harmful-brain-activity-classification/train.csv\")\ntest_df_org  = pd.read_csv(\"/kaggle/input/hms-harmful-brain-activity-classification/test.csv\")\nsample_df_org = pd.read_csv(\"/kaggle/input/hms-harmful-brain-activity-classification/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.025769Z","iopub.execute_input":"2024-03-03T22:07:13.027001Z","iopub.status.idle":"2024-03-03T22:07:13.401608Z","shell.execute_reply.started":"2024-03-03T22:07:13.026948Z","shell.execute_reply":"2024-03-03T22:07:13.400344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df_org.head(n=5)","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.403272Z","iopub.execute_input":"2024-03-03T22:07:13.403740Z","iopub.status.idle":"2024-03-03T22:07:13.437855Z","shell.execute_reply.started":"2024-03-03T22:07:13.403697Z","shell.execute_reply":"2024-03-03T22:07:13.436475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df_org.info()","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.441442Z","iopub.execute_input":"2024-03-03T22:07:13.442827Z","iopub.status.idle":"2024-03-03T22:07:13.490823Z","shell.execute_reply.started":"2024-03-03T22:07:13.442782Z","shell.execute_reply":"2024-03-03T22:07:13.489580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df_org[train_df_org.eeg_label_offset_seconds != train_df_org.spectrogram_label_offset_seconds]","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.492440Z","iopub.execute_input":"2024-03-03T22:07:13.493721Z","iopub.status.idle":"2024-03-03T22:07:13.534960Z","shell.execute_reply.started":"2024-03-03T22:07:13.493674Z","shell.execute_reply":"2024-03-03T22:07:13.533341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train_df_org['patient_id'].nunique())\nprint(train_df_org['eeg_id'].nunique())\nprint(train_df_org['expert_consensus'].nunique())\nprint(train_df_org['expert_consensus'].unique())","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.538420Z","iopub.execute_input":"2024-03-03T22:07:13.539463Z","iopub.status.idle":"2024-03-03T22:07:13.573392Z","shell.execute_reply.started":"2024-03-03T22:07:13.539423Z","shell.execute_reply":"2024-03-03T22:07:13.572451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"I will remove (eeg_label_offset_seconds and spectrogram_label_offset_seconds) with the sub ids columns as I think they don't have a big effect","metadata":{}},{"cell_type":"code","source":"train_df = train_df_org\ntrain_df.drop(columns= ['eeg_sub_id', 'eeg_label_offset_seconds', 'spectrogram_id', 'spectrogram_sub_id', 'spectrogram_label_offset_seconds',\n                        'label_id', 'patient_id', 'expert_consensus'], inplace= True)\ntrain_df.info()","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.574751Z","iopub.execute_input":"2024-03-03T22:07:13.575073Z","iopub.status.idle":"2024-03-03T22:07:13.589304Z","shell.execute_reply.started":"2024-03-03T22:07:13.575044Z","shell.execute_reply":"2024-03-03T22:07:13.588398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.590811Z","iopub.execute_input":"2024-03-03T22:07:13.591379Z","iopub.status.idle":"2024-03-03T22:07:13.603315Z","shell.execute_reply.started":"2024-03-03T22:07:13.591351Z","shell.execute_reply":"2024-03-03T22:07:13.602081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_df_org","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.604961Z","iopub.execute_input":"2024-03-03T22:07:13.605639Z","iopub.status.idle":"2024-03-03T22:07:13.618366Z","shell.execute_reply.started":"2024-03-03T22:07:13.605608Z","shell.execute_reply":"2024-03-03T22:07:13.617431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.sort_values(['eeg_id'], inplace= True, ignore_index=True)\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.622494Z","iopub.execute_input":"2024-03-03T22:07:13.623577Z","iopub.status.idle":"2024-03-03T22:07:13.651234Z","shell.execute_reply.started":"2024-03-03T22:07:13.623540Z","shell.execute_reply":"2024-03-03T22:07:13.650133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d = 0\nfor i in train_df['eeg_id']:\n    d += 1\n    if d < 8:\n        print(i)","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.652628Z","iopub.execute_input":"2024-03-03T22:07:13.652966Z","iopub.status.idle":"2024-03-03T22:07:13.697437Z","shell.execute_reply.started":"2024-03-03T22:07:13.652938Z","shell.execute_reply":"2024-03-03T22:07:13.696553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_eegs_dir = \"/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/\"\neeg_data = pd.read_parquet(train_eegs_dir + '568657.parquet')\neeg_data.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.698841Z","iopub.execute_input":"2024-03-03T22:07:13.699418Z","iopub.status.idle":"2024-03-03T22:07:13.903328Z","shell.execute_reply.started":"2024-03-03T22:07:13.699387Z","shell.execute_reply":"2024-03-03T22:07:13.902187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_spect_dir = \"/kaggle/input/hms-harmful-brain-activity-classification/train_spectrograms/\"\nspect_data = pd.read_parquet(train_spect_dir + '353733.parquet')\nspect_data","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.905007Z","iopub.execute_input":"2024-03-03T22:07:13.905616Z","iopub.status.idle":"2024-03-03T22:07:13.996998Z","shell.execute_reply.started":"2024-03-03T22:07:13.905586Z","shell.execute_reply":"2024-03-03T22:07:13.996169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.drop_duplicates(inplace=True)\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:13.998085Z","iopub.execute_input":"2024-03-03T22:07:13.998596Z","iopub.status.idle":"2024-03-03T22:07:14.033380Z","shell.execute_reply.started":"2024-03-03T22:07:13.998567Z","shell.execute_reply":"2024-03-03T22:07:14.031952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train_df.eeg_id.unique())","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:14.034865Z","iopub.execute_input":"2024-03-03T22:07:14.035184Z","iopub.status.idle":"2024-03-03T22:07:14.044224Z","shell.execute_reply.started":"2024-03-03T22:07:14.035158Z","shell.execute_reply":"2024-03-03T22:07:14.042894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eeg_data.info()","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:14.046350Z","iopub.execute_input":"2024-03-03T22:07:14.046929Z","iopub.status.idle":"2024-03-03T22:07:14.063728Z","shell.execute_reply.started":"2024-03-03T22:07:14.046883Z","shell.execute_reply":"2024-03-03T22:07:14.062063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eeg_data.isna().sum()","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:14.065223Z","iopub.execute_input":"2024-03-03T22:07:14.065603Z","iopub.status.idle":"2024-03-03T22:07:14.076525Z","shell.execute_reply.started":"2024-03-03T22:07:14.065573Z","shell.execute_reply":"2024-03-03T22:07:14.075541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eeg_data","metadata":{"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2024-03-03T22:07:14.078086Z","iopub.execute_input":"2024-03-03T22:07:14.078762Z","iopub.status.idle":"2024-03-03T22:07:14.114312Z","shell.execute_reply.started":"2024-03-03T22:07:14.078727Z","shell.execute_reply":"2024-03-03T22:07:14.112925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eeg_data.max(axis=0)","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:14.115934Z","iopub.execute_input":"2024-03-03T22:07:14.116273Z","iopub.status.idle":"2024-03-03T22:07:14.128160Z","shell.execute_reply.started":"2024-03-03T22:07:14.116245Z","shell.execute_reply":"2024-03-03T22:07:14.126672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = eeg_data/eeg_data.max(axis=0)\na","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:14.129828Z","iopub.execute_input":"2024-03-03T22:07:14.130625Z","iopub.status.idle":"2024-03-03T22:07:14.170234Z","shell.execute_reply.started":"2024-03-03T22:07:14.130589Z","shell.execute_reply":"2024-03-03T22:07:14.168928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\neeg_data_tensor = torch.tensor(a.values, dtype= torch.float)\neeg_data_tensor","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:14.171834Z","iopub.execute_input":"2024-03-03T22:07:14.172211Z","iopub.status.idle":"2024-03-03T22:07:14.295461Z","shell.execute_reply.started":"2024-03-03T22:07:14.172179Z","shell.execute_reply":"2024-03-03T22:07:14.293676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eeg_data_tensor.shape","metadata":{"execution":{"iopub.status.busy":"2024-03-03T22:07:28.702062Z","iopub.execute_input":"2024-03-03T22:07:28.702946Z","iopub.status.idle":"2024-03-03T22:07:28.709237Z","shell.execute_reply.started":"2024-03-03T22:07:28.702913Z","shell.execute_reply":"2024-03-03T22:07:28.708246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}