{"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":7469972,"sourceType":"competition"}],"dockerImageVersionId":30626,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport os","metadata":{"execution":{"iopub.status.busy":"2024-01-17T14:12:19.568380Z","iopub.execute_input":"2024-01-17T14:12:19.569120Z","iopub.status.idle":"2024-01-17T14:12:20.022891Z","shell.execute_reply.started":"2024-01-17T14:12:19.569081Z","shell.execute_reply":"2024-01-17T14:12:20.021903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/hms-harmful-brain-activity-classification/train.csv')\ntrain.shape","metadata":{"execution":{"iopub.status.busy":"2024-01-17T14:12:27.116745Z","iopub.execute_input":"2024-01-17T14:12:27.117328Z","iopub.status.idle":"2024-01-17T14:12:27.417123Z","shell.execute_reply.started":"2024-01-17T14:12:27.117284Z","shell.execute_reply":"2024-01-17T14:12:27.415991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv('/kaggle/input/hms-harmful-brain-activity-classification/test.csv')\ntest","metadata":{"execution":{"iopub.status.busy":"2024-01-17T14:12:29.606553Z","iopub.execute_input":"2024-01-17T14:12:29.607654Z","iopub.status.idle":"2024-01-17T14:12:29.632035Z","shell.execute_reply.started":"2024-01-17T14:12:29.607606Z","shell.execute_reply":"2024-01-17T14:12:29.631095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_eeg = pd.read_parquet('/kaggle/input/hms-harmful-brain-activity-classification/test_eegs/3911565283.parquet')\ntest_eeg","metadata":{"execution":{"iopub.status.busy":"2024-01-17T14:12:30.554913Z","iopub.execute_input":"2024-01-17T14:12:30.555516Z","iopub.status.idle":"2024-01-17T14:12:30.845166Z","shell.execute_reply.started":"2024-01-17T14:12:30.555483Z","shell.execute_reply":"2024-01-17T14:12:30.843954Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['eeg_id'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-01-17T14:12:32.976769Z","iopub.execute_input":"2024-01-17T14:12:32.977324Z","iopub.status.idle":"2024-01-17T14:12:32.996019Z","shell.execute_reply.started":"2024-01-17T14:12:32.977277Z","shell.execute_reply":"2024-01-17T14:12:32.994555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['eeg_id'].size","metadata":{"execution":{"iopub.status.busy":"2024-01-17T14:12:33.664704Z","iopub.execute_input":"2024-01-17T14:12:33.666055Z","iopub.status.idle":"2024-01-17T14:12:33.675080Z","shell.execute_reply.started":"2024-01-17T14:12:33.666004Z","shell.execute_reply":"2024-01-17T14:12:33.673624Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['spectrogram_id'].size","metadata":{"execution":{"iopub.status.busy":"2024-01-17T14:12:33.902367Z","iopub.execute_input":"2024-01-17T14:12:33.902912Z","iopub.status.idle":"2024-01-17T14:12:33.912134Z","shell.execute_reply.started":"2024-01-17T14:12:33.902868Z","shell.execute_reply":"2024-01-17T14:12:33.910644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Explore Train_EEG","metadata":{}},{"cell_type":"code","source":"train_eeg_1 = pd.read_parquet('/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/1001369401.parquet')\ntrain_eeg_1","metadata":{"execution":{"iopub.status.busy":"2024-01-17T14:12:34.791484Z","iopub.execute_input":"2024-01-17T14:12:34.792004Z","iopub.status.idle":"2024-01-17T14:12:34.854645Z","shell.execute_reply.started":"2024-01-17T14:12:34.791964Z","shell.execute_reply":"2024-01-17T14:12:34.853383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"directory_EEG = \"/kaggle/input/hms-harmful-brain-activity-classification/train_eegs\"","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:21.027748Z","iopub.execute_input":"2024-01-15T18:32:21.028594Z","iopub.status.idle":"2024-01-15T18:32:21.035361Z","shell.execute_reply.started":"2024-01-15T18:32:21.028542Z","shell.execute_reply":"2024-01-15T18:32:21.033370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_files_EEG = os.listdir(directory_EEG)","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:21.216399Z","iopub.execute_input":"2024-01-15T18:32:21.216841Z","iopub.status.idle":"2024-01-15T18:32:21.502987Z","shell.execute_reply.started":"2024-01-15T18:32:21.216807Z","shell.execute_reply":"2024-01-15T18:32:21.502113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_filename = \"1000913311.parquet\"\n\n# Construct the full path\ntarget_file_path = os.path.join(directory_EEG, target_filename)\n\n# Check if the file exists\nif os.path.exists(target_file_path):\n    print(f\"Found target file: {target_file_path}\")\nelse:\n    print(f\"File '{target_filename}' not found in the directory.\")","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:22.247114Z","iopub.execute_input":"2024-01-15T18:32:22.248352Z","iopub.status.idle":"2024-01-15T18:32:22.257170Z","shell.execute_reply.started":"2024-01-15T18:32:22.248305Z","shell.execute_reply":"2024-01-15T18:32:22.255821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(all_files_EEG)","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:22.424740Z","iopub.execute_input":"2024-01-15T18:32:22.425178Z","iopub.status.idle":"2024-01-15T18:32:22.432222Z","shell.execute_reply.started":"2024-01-15T18:32:22.425144Z","shell.execute_reply":"2024-01-15T18:32:22.431094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columns = train_eeg_1.columns\nnum_plots = len(columns)\nnum_cols = 2\nnum_rows = (num_plots + num_cols - 1) // num_cols\n\nfig, axes = plt.subplots(num_rows, num_cols, figsize=(12, num_rows * 4))  \n\nfor i, col in enumerate(columns):\n    ax = axes[i // num_cols, i % num_cols] if num_rows > 1 else axes[i % num_cols]\n    ax.plot(train_eeg_1[col])\n    ax.set_title(col + ' data')\n    ax.set_xlabel('Index')\n    ax.set_ylabel('Values')\n\nplt.tight_layout(pad=3.0)  \nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:22.696375Z","iopub.execute_input":"2024-01-15T18:32:22.697298Z","iopub.status.idle":"2024-01-15T18:32:28.036669Z","shell.execute_reply.started":"2024-01-15T18:32:22.697257Z","shell.execute_reply":"2024-01-15T18:32:28.035524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Explore Train Spectrogram","metadata":{}},{"cell_type":"code","source":"spectrogram_data = pd.read_parquet('/kaggle/input/hms-harmful-brain-activity-classification/train_spectrograms/1000189855.parquet')\nspectrogram_data","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:28.038543Z","iopub.execute_input":"2024-01-15T18:32:28.039676Z","iopub.status.idle":"2024-01-15T18:32:28.159348Z","shell.execute_reply.started":"2024-01-15T18:32:28.039630Z","shell.execute_reply":"2024-01-15T18:32:28.158141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"directory = \"/kaggle/input/hms-harmful-brain-activity-classification/train_spectrograms\"","metadata":{"execution":{"iopub.status.busy":"2024-01-16T18:17:15.363082Z","iopub.execute_input":"2024-01-16T18:17:15.363435Z","iopub.status.idle":"2024-01-16T18:17:15.368486Z","shell.execute_reply.started":"2024-01-16T18:17:15.363408Z","shell.execute_reply":"2024-01-16T18:17:15.367634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_files = os.listdir(directory)","metadata":{"execution":{"iopub.status.busy":"2024-01-16T18:17:15.968865Z","iopub.execute_input":"2024-01-16T18:17:15.969196Z","iopub.status.idle":"2024-01-16T18:17:16.219272Z","shell.execute_reply.started":"2024-01-16T18:17:15.969170Z","shell.execute_reply":"2024-01-16T18:17:16.218539Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(all_files)","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:33.662089Z","iopub.execute_input":"2024-01-15T18:32:33.662722Z","iopub.status.idle":"2024-01-15T18:32:33.669261Z","shell.execute_reply.started":"2024-01-15T18:32:33.662679Z","shell.execute_reply":"2024-01-15T18:32:33.668112Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(all_files_EEG) == len(all_files)","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:33.700281Z","iopub.execute_input":"2024-01-15T18:32:33.700669Z","iopub.status.idle":"2024-01-15T18:32:33.711454Z","shell.execute_reply.started":"2024-01-15T18:32:33.700637Z","shell.execute_reply":"2024-01-15T18:32:33.710003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test =pd.read_csv('/kaggle/input/hms-harmful-brain-activity-classification/test.csv')\ntest","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:33.731404Z","iopub.execute_input":"2024-01-15T18:32:33.732390Z","iopub.status.idle":"2024-01-15T18:32:33.745584Z","shell.execute_reply.started":"2024-01-15T18:32:33.732348Z","shell.execute_reply":"2024-01-15T18:32:33.744216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_sub = pd.read_csv('/kaggle/input/hms-harmful-brain-activity-classification/sample_submission.csv')\nsample_sub","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:33.760506Z","iopub.execute_input":"2024-01-15T18:32:33.761644Z","iopub.status.idle":"2024-01-15T18:32:33.782981Z","shell.execute_reply.started":"2024-01-15T18:32:33.761603Z","shell.execute_reply":"2024-01-15T18:32:33.781771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"targets = ['seizure_vote','lpd_vote','lrda_vote','grda_vote','other_vote']","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:33.789855Z","iopub.execute_input":"2024-01-15T18:32:33.790318Z","iopub.status.idle":"2024-01-15T18:32:33.795722Z","shell.execute_reply.started":"2024-01-15T18:32:33.790286Z","shell.execute_reply":"2024-01-15T18:32:33.794242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['target'] = train.groupby('eeg_id')[['expert_consensus']].agg('first')","metadata":{"execution":{"iopub.status.busy":"2024-01-15T18:32:33.821194Z","iopub.execute_input":"2024-01-15T18:32:33.821794Z","iopub.status.idle":"2024-01-15T18:32:33.870096Z","shell.execute_reply.started":"2024-01-15T18:32:33.821757Z","shell.execute_reply":"2024-01-15T18:32:33.868855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}