{"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":"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","_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Imports","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2024-01-10T16:27:57.128140Z","iopub.execute_input":"2024-01-10T16:27:57.128800Z","iopub.status.idle":"2024-01-10T16:27:57.729227Z","shell.execute_reply.started":"2024-01-10T16:27:57.128747Z","shell.execute_reply":"2024-01-10T16:27:57.727783Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Reading Train and Test","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/hms-harmful-brain-activity-classification/train.csv\")\ntrain","metadata":{"execution":{"iopub.status.busy":"2024-01-10T16:28:28.524041Z","iopub.execute_input":"2024-01-10T16:28:28.524477Z","iopub.status.idle":"2024-01-10T16:28:28.567460Z","shell.execute_reply.started":"2024-01-10T16:28:28.524412Z","shell.execute_reply":"2024-01-10T16:28:28.566620Z"},"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-10T16:28:43.959771Z","iopub.execute_input":"2024-01-10T16:28:43.960181Z","iopub.status.idle":"2024-01-10T16:28:43.981911Z","shell.execute_reply.started":"2024-01-10T16:28:43.960147Z","shell.execute_reply":"2024-01-10T16:28:43.980519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission = pd.read_csv(\"/kaggle/input/hms-harmful-brain-activity-classification/sample_submission.csv\")\nsample_submission","metadata":{"execution":{"iopub.status.busy":"2024-01-10T16:29:39.708664Z","iopub.execute_input":"2024-01-10T16:29:39.709048Z","iopub.status.idle":"2024-01-10T16:29:39.731333Z","shell.execute_reply.started":"2024-01-10T16:29:39.709008Z","shell.execute_reply":"2024-01-10T16:29:39.729910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EEGs","metadata":{}},{"cell_type":"code","source":"print(\"Train eeg files: \")\n! ls /kaggle/input/hms-harmful-brain-activity-classification/train_eegs | wc -l\nprint(\"Size of train eegs\")\n! du -sh /kaggle/input/hms-harmful-brain-activity-classification/train_eegs","metadata":{"execution":{"iopub.status.busy":"2024-01-10T16:37:59.833910Z","iopub.execute_input":"2024-01-10T16:37:59.834521Z","iopub.status.idle":"2024-01-10T16:38:29.902188Z","shell.execute_reply.started":"2024-01-10T16:37:59.834481Z","shell.execute_reply":"2024-01-10T16:38:29.900401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_train_eeg = pd.read_parquet(\"/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/1000913311.parquet\")\nsample_train_eeg","metadata":{"execution":{"iopub.status.busy":"2024-01-10T16:38:29.905066Z","iopub.execute_input":"2024-01-10T16:38:29.905513Z","iopub.status.idle":"2024-01-10T16:38:30.360966Z","shell.execute_reply.started":"2024-01-10T16:38:29.905473Z","shell.execute_reply":"2024-01-10T16:38:30.360021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\n\n\n\n# Set Seaborn style\nsns.set(style=\"whitegrid\", font_scale=1.2)\n\n# Create a figure with subplots\nfig, ax = plt.subplots(20, figsize=(10, 50), sharex=True)\n\n# Generate a line plot for each column in the DataFrame using Seaborn\nfor i, column in enumerate(sample_train_eeg.columns):\n    sns.lineplot(x=sample_train_eeg.index, y=sample_train_eeg[column], ax=ax[i], label=column, linewidth=2)\n    ax[i].set_title(str(column))\n\n# Add overall title and axis labels\nfig.suptitle('Simulated Data Line Chart', fontsize=16)\nfig.text(0.5, 0.04, 'Index', ha='center', fontsize=14)\nfig.text(0.04, 0.5, 'Values', va='center', rotation='vertical', fontsize=14)\n\n# Adjust layout for better spacing\nplt.tight_layout(rect=[0, 0.03, 1, 0.95])\n\n# Display the plot\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-01-10T16:44:01.697302Z","iopub.execute_input":"2024-01-10T16:44:01.697768Z","iopub.status.idle":"2024-01-10T16:44:12.084246Z","shell.execute_reply.started":"2024-01-10T16:44:01.697732Z","shell.execute_reply":"2024-01-10T16:44:12.082612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Spectogram","metadata":{}},{"cell_type":"code","source":"sample_train_spectrogram = pd.read_parquet(\"/kaggle/input/hms-harmful-brain-activity-classification/train_spectrograms/1000086677.parquet\")\nsample_train_spectrogram","metadata":{"execution":{"iopub.status.busy":"2024-01-10T16:44:53.136187Z","iopub.execute_input":"2024-01-10T16:44:53.136716Z","iopub.status.idle":"2024-01-10T16:44:53.231046Z","shell.execute_reply.started":"2024-01-10T16:44:53.136675Z","shell.execute_reply":"2024-01-10T16:44:53.229529Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_spectrogram(spectrogram_path):\n    sample_spect = pd.read_parquet(spectrogram_path)\n    \n    split_spect = {\n        \"LL\": sample_spect.filter(regex='^LL', axis=1),\n        \"RL\": sample_spect.filter(regex='^RL', axis=1),\n        \"RP\": sample_spect.filter(regex='^RP', axis=1),\n        \"LP\": sample_spect.filter(regex='^LP', axis=1),\n    }\n    \n    fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(15, 12), sharex=True, sharey=True)\n    axes = axes.flatten()\n    label_interval = 5\n\n    for i, split_name in enumerate(split_spect.keys()):\n        ax = axes[i]\n        img = ax.imshow(np.log(split_spect[split_name]).T, cmap='viridis', aspect='auto', origin='lower')\n        cbar = fig.colorbar(img, ax=ax)\n        cbar.set_label('Log(Value)')\n        ax.set_title(split_name)\n\n        if i // 2 == 1:\n            ax.set_xlabel(\"Time\")\n        if i % 2 == 0:\n            ax.set_ylabel(\"Frequency (Hz)\")\n\n        ax.set_yticks(np.arange(len(split_spect[split_name].columns))[::label_interval])\n        ax.set_yticklabels([column_name[3:] for column_name in split_spect[split_name].columns][::label_interval])\n\n    # Add a common title for the entire figure\n    fig.suptitle('Spectrogram Analysis', fontsize=16)\n\n    # Adjust layout for better spacing\n    plt.tight_layout(rect=[0, 0.03, 1, 0.95])\n    \n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-01-10T16:50:43.415584Z","iopub.execute_input":"2024-01-10T16:50:43.416023Z","iopub.status.idle":"2024-01-10T16:50:43.427293Z","shell.execute_reply.started":"2024-01-10T16:50:43.415990Z","shell.execute_reply":"2024-01-10T16:50:43.425913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(\"/kaggle/input/hms-harmful-brain-activity-classification/train_spectrograms/1000189855.parquet\")","metadata":{"execution":{"iopub.status.busy":"2024-01-10T16:50:46.287301Z","iopub.execute_input":"2024-01-10T16:50:46.288717Z","iopub.status.idle":"2024-01-10T16:50:49.323746Z","shell.execute_reply.started":"2024-01-10T16:50:46.288657Z","shell.execute_reply":"2024-01-10T16:50:49.321966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}