{"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":59093,"databundleVersionId":7457433,"sourceType":"competition"}],"dockerImageVersionId":30626,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## Table of Contents\n* [File Overview](#files)\n* [EEG File Example](#ex_EEG)\n* [Spectrogram File Example](#ex_spec)","metadata":{}},{"cell_type":"code","source":"# packages\n\n# standard\nimport numpy as np\nimport pandas as pd\nimport time\n\n# plot\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-01-09T21:13:05.159875Z","iopub.execute_input":"2024-01-09T21:13:05.160791Z","iopub.status.idle":"2024-01-09T21:13:07.231544Z","shell.execute_reply.started":"2024-01-09T21:13:05.160745Z","shell.execute_reply":"2024-01-09T21:13:07.230291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# configs\npd.set_option('display.max_columns', None) # we want to display all columns in this notebook\n\n# aesthetics\ndefault_color_1 = 'darkblue'\ndefault_color_2 = 'darkgreen'\ndefault_color_3 = 'darkred'","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:13:35.969838Z","iopub.execute_input":"2024-01-09T21:13:35.970996Z","iopub.status.idle":"2024-01-09T21:13:35.977784Z","shell.execute_reply.started":"2024-01-09T21:13:35.970946Z","shell.execute_reply":"2024-01-09T21:13:35.976625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id='files'></a>\n# File Overview","metadata":{}},{"cell_type":"code","source":"!ls -l '../input/hms-harmful-brain-activity-classification'","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:13:37.646538Z","iopub.execute_input":"2024-01-09T21:13:37.647559Z","iopub.status.idle":"2024-01-09T21:13:38.759678Z","shell.execute_reply.started":"2024-01-09T21:13:37.647511Z","shell.execute_reply":"2024-01-09T21:13:38.758125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls -l '../input/hms-harmful-brain-activity-classification/train_spectrograms'","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-01-09T21:13:41.363437Z","iopub.execute_input":"2024-01-09T21:13:41.365129Z","iopub.status.idle":"2024-01-09T21:13:43.406755Z","shell.execute_reply.started":"2024-01-09T21:13:41.365044Z","shell.execute_reply":"2024-01-09T21:13:43.4053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls -l '../input/hms-harmful-brain-activity-classification/train_eegs'","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-01-09T21:13:57.430318Z","iopub.execute_input":"2024-01-09T21:13:57.430716Z","iopub.status.idle":"2024-01-09T21:14:00.08002Z","shell.execute_reply.started":"2024-01-09T21:13:57.43068Z","shell.execute_reply":"2024-01-09T21:14:00.078647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id='ex_EEG'></a>\n# EEG File Example","metadata":{}},{"cell_type":"code","source":"# load an EEG file\ndf_eeg = pd.read_parquet('../input/hms-harmful-brain-activity-classification/train_eegs/1000913311.parquet')","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:14:02.134406Z","iopub.execute_input":"2024-01-09T21:14:02.134899Z","iopub.status.idle":"2024-01-09T21:14:02.48566Z","shell.execute_reply.started":"2024-01-09T21:14:02.134835Z","shell.execute_reply":"2024-01-09T21:14:02.484744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# preview\ndf_eeg.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:14:12.071317Z","iopub.execute_input":"2024-01-09T21:14:12.072585Z","iopub.status.idle":"2024-01-09T21:14:12.107177Z","shell.execute_reply.started":"2024-01-09T21:14:12.072528Z","shell.execute_reply":"2024-01-09T21:14:12.10584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show structure\ndf_eeg.info()","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:14:16.043254Z","iopub.execute_input":"2024-01-09T21:14:16.043639Z","iopub.status.idle":"2024-01-09T21:14:16.072308Z","shell.execute_reply.started":"2024-01-09T21:14:16.043608Z","shell.execute_reply":"2024-01-09T21:14:16.070703Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# basis stats\ndf_eeg.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:14:18.144994Z","iopub.execute_input":"2024-01-09T21:14:18.145956Z","iopub.status.idle":"2024-01-09T21:14:18.237366Z","shell.execute_reply.started":"2024-01-09T21:14:18.145893Z","shell.execute_reply":"2024-01-09T21:14:18.236044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# list of features\nfeatures_eeg = ['Fp1', 'F3', 'C3', 'P3', 'F7', \n                'T3', 'T5', 'O1', 'Fz', 'Cz', 'Pz',\n                'Fp2', 'F4', 'C4', 'P4', 'F8',\n                'T4', 'T6', 'O2', 'EKG']","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:14:20.746637Z","iopub.execute_input":"2024-01-09T21:14:20.747343Z","iopub.status.idle":"2024-01-09T21:14:20.754206Z","shell.execute_reply.started":"2024-01-09T21:14:20.747305Z","shell.execute_reply":"2024-01-09T21:14:20.752378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plot all features\nfor f in features_eeg:\n    plt.figure(figsize=(12,3))\n    plt.plot(df_eeg[f], color=default_color_1)\n    plt.title(f)\n    plt.grid()\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:14:23.833198Z","iopub.execute_input":"2024-01-09T21:14:23.834625Z","iopub.status.idle":"2024-01-09T21:14:32.676022Z","shell.execute_reply.started":"2024-01-09T21:14:23.834568Z","shell.execute_reply":"2024-01-09T21:14:32.674487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id='ex_spec'></a>\n# Spectrogram File Example","metadata":{}},{"cell_type":"code","source":"# load spectrogram file\ndf_spec = pd.read_parquet('../input/hms-harmful-brain-activity-classification/train_spectrograms/1000086677.parquet')","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:14:36.51351Z","iopub.execute_input":"2024-01-09T21:14:36.513934Z","iopub.status.idle":"2024-01-09T21:14:36.572113Z","shell.execute_reply.started":"2024-01-09T21:14:36.513901Z","shell.execute_reply":"2024-01-09T21:14:36.570997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# preview\ndf_spec.head()","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:14:38.956051Z","iopub.execute_input":"2024-01-09T21:14:38.957421Z","iopub.status.idle":"2024-01-09T21:14:39.394351Z","shell.execute_reply.started":"2024-01-09T21:14:38.95737Z","shell.execute_reply":"2024-01-09T21:14:39.393016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show structure\ndf_spec.info(verbose=True, show_counts=True)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-01-09T21:14:42.07639Z","iopub.execute_input":"2024-01-09T21:14:42.076809Z","iopub.status.idle":"2024-01-09T21:14:42.122388Z","shell.execute_reply.started":"2024-01-09T21:14:42.076776Z","shell.execute_reply":"2024-01-09T21:14:42.120802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# basis stats\ndf_spec.describe()","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:14:48.508496Z","iopub.execute_input":"2024-01-09T21:14:48.508969Z","iopub.status.idle":"2024-01-09T21:14:49.851312Z","shell.execute_reply.started":"2024-01-09T21:14:48.508933Z","shell.execute_reply":"2024-01-09T21:14:49.850012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Some plots:","metadata":{}},{"cell_type":"code","source":"# plotting function\ndef plot_spec(i_frequency):\n    feature_1 = 'LL_' + i_frequency\n    feature_2 = 'RL_' + i_frequency\n    feature_3 = 'RP_' + i_frequency\n    feature_4 = 'LP_' + i_frequency\n    plt.figure(figsize=(8,3))\n    plt.scatter(df_spec.time, df_spec[feature_1], label='LL')\n    plt.scatter(df_spec.time, df_spec[feature_2], label='RL')\n    plt.scatter(df_spec.time, df_spec[feature_3], label='RP')\n    plt.scatter(df_spec.time, df_spec[feature_4], label='LP')\n    plt.legend(loc='upper right')\n    plt.title('Frequency=' + i_frequency)\n    plt.grid()\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:15:03.318475Z","iopub.execute_input":"2024-01-09T21:15:03.3189Z","iopub.status.idle":"2024-01-09T21:15:03.327689Z","shell.execute_reply.started":"2024-01-09T21:15:03.31887Z","shell.execute_reply":"2024-01-09T21:15:03.326743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plot for a few frequencies\nfrequencies = ['0.59', '3.91', '10.16', '19.92']\nfor freq in frequencies:\n    plot_spec(freq)","metadata":{"execution":{"iopub.status.busy":"2024-01-09T21:15:04.959229Z","iopub.execute_input":"2024-01-09T21:15:04.963083Z","iopub.status.idle":"2024-01-09T21:15:06.680013Z","shell.execute_reply.started":"2024-01-09T21:15:04.963021Z","shell.execute_reply":"2024-01-09T21:15:06.678397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Work in progress","metadata":{}}]}