{"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":30673,"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 \n\nimport matplotlib.pyplot as plt \nimport seaborn as sns \n\nimport tensorflow as tf \n\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.model_selection import train_test_split\n\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout\n\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.ensemble import RandomForestClassifier\n\nfrom sklearn.svm import SVC\nfrom sklearn.metrics import accuracy_score\n\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:41.258222Z","iopub.execute_input":"2024-04-01T14:10:41.258651Z","iopub.status.idle":"2024-04-01T14:10:41.264866Z","shell.execute_reply.started":"2024-04-01T14:10:41.258620Z","shell.execute_reply":"2024-04-01T14:10:41.263859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv(\"/kaggle/input/hms-harmful-brain-activity-classification/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:42.123604Z","iopub.execute_input":"2024-04-01T14:10:42.124612Z","iopub.status.idle":"2024-04-01T14:10:42.227014Z","shell.execute_reply.started":"2024-04-01T14:10:42.124585Z","shell.execute_reply":"2024-04-01T14:10:42.226345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:42.524439Z","iopub.execute_input":"2024-04-01T14:10:42.525550Z","iopub.status.idle":"2024-04-01T14:10:42.542427Z","shell.execute_reply.started":"2024-04-01T14:10:42.525517Z","shell.execute_reply":"2024-04-01T14:10:42.540618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Missing values before preprocessing:\")\nprint(train_data.isnull().sum())","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:42.783074Z","iopub.execute_input":"2024-04-01T14:10:42.783515Z","iopub.status.idle":"2024-04-01T14:10:42.797013Z","shell.execute_reply.started":"2024-04-01T14:10:42.783480Z","shell.execute_reply":"2024-04-01T14:10:42.795370Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"unique_values = train_data['expert_consensus'].unique()\n\nprint(unique_values)\n","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:42.945890Z","iopub.execute_input":"2024-04-01T14:10:42.946956Z","iopub.status.idle":"2024-04-01T14:10:42.960549Z","shell.execute_reply.started":"2024-04-01T14:10:42.946890Z","shell.execute_reply":"2024-04-01T14:10:42.958777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\n\ncustom_colors = [\"#1f77b4\", \"#ff7f0e\", \"#2ca02c\", \"#d62728\", \"#9467bd\", \"#8c564b\"]\n\n\nplt.figure(figsize=(8, 6))\nsns.countplot(x='expert_consensus', data=train_data, palette=custom_colors)\nplt.title('Distribution of Expert Consensus Labels')\nplt.xlabel('Expert Consensus Labels')\nplt.ylabel('Count')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:43.120254Z","iopub.execute_input":"2024-04-01T14:10:43.120711Z","iopub.status.idle":"2024-04-01T14:10:43.736616Z","shell.execute_reply.started":"2024-04-01T14:10:43.120677Z","shell.execute_reply":"2024-04-01T14:10:43.735357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_encoder = LabelEncoder()\ntrain_data['expert_consensus'] = label_encoder.fit_transform(train_data['expert_consensus'])","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:43.738816Z","iopub.execute_input":"2024-04-01T14:10:43.739200Z","iopub.status.idle":"2024-04-01T14:10:43.765754Z","shell.execute_reply.started":"2024-04-01T14:10:43.739167Z","shell.execute_reply":"2024-04-01T14:10:43.763765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head(7)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:43.767119Z","iopub.execute_input":"2024-04-01T14:10:43.767462Z","iopub.status.idle":"2024-04-01T14:10:43.783537Z","shell.execute_reply.started":"2024-04-01T14:10:43.767433Z","shell.execute_reply":"2024-04-01T14:10:43.782282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X=train_data[['eeg_label_offset_seconds', 'spectrogram_label_offset_seconds', 'patient_id']]\nY=train_data['expert_consensus']","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:44.019187Z","iopub.execute_input":"2024-04-01T14:10:44.019584Z","iopub.status.idle":"2024-04-01T14:10:44.025374Z","shell.execute_reply.started":"2024-04-01T14:10:44.019556Z","shell.execute_reply":"2024-04-01T14:10:44.024585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nX_train,X_test,y_train,y_test=train_test_split(X,Y,test_size=0.2,random_state=42)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:44.096973Z","iopub.execute_input":"2024-04-01T14:10:44.097737Z","iopub.status.idle":"2024-04-01T14:10:44.112449Z","shell.execute_reply.started":"2024-04-01T14:10:44.097710Z","shell.execute_reply":"2024-04-01T14:10:44.110449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nscaler = StandardScaler()\nX_train_scaled = scaler.fit_transform(X_train)\nX_test_scaled = scaler.transform(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:44.188026Z","iopub.execute_input":"2024-04-01T14:10:44.188652Z","iopub.status.idle":"2024-04-01T14:10:44.200340Z","shell.execute_reply.started":"2024-04-01T14:10:44.188619Z","shell.execute_reply":"2024-04-01T14:10:44.199038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_scaled","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:44.284813Z","iopub.execute_input":"2024-04-01T14:10:44.285166Z","iopub.status.idle":"2024-04-01T14:10:44.292382Z","shell.execute_reply.started":"2024-04-01T14:10:44.285137Z","shell.execute_reply":"2024-04-01T14:10:44.291206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_encoded = pd.get_dummies(X_train, columns=['patient_id'])\nX_test_encoded = pd.get_dummies(X_test, columns=['patient_id'])","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:44.347660Z","iopub.execute_input":"2024-04-01T14:10:44.348069Z","iopub.status.idle":"2024-04-01T14:10:44.473914Z","shell.execute_reply.started":"2024-04-01T14:10:44.348038Z","shell.execute_reply":"2024-04-01T14:10:44.472942Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_encoded","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:44.488844Z","iopub.status.idle":"2024-04-01T14:10:44.522930Z","shell.execute_reply.started":"2024-04-01T14:10:44.489193Z","shell.execute_reply":"2024-04-01T14:10:44.521401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsClassifier\nknn=KNeighborsClassifier()\nknn.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:44.566618Z","iopub.execute_input":"2024-04-01T14:10:44.567063Z","iopub.status.idle":"2024-04-01T14:10:44.635657Z","shell.execute_reply.started":"2024-04-01T14:10:44.567029Z","shell.execute_reply":"2024-04-01T14:10:44.633889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import cross_val_score\nscores = cross_val_score(knn, X_train, y_train, cv=5)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:44.638348Z","iopub.execute_input":"2024-04-01T14:10:44.638737Z","iopub.status.idle":"2024-04-01T14:10:47.846579Z","shell.execute_reply.started":"2024-04-01T14:10:44.638703Z","shell.execute_reply":"2024-04-01T14:10:47.844351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction=knn.predict(X_test)\nprint(prediction)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:47.848991Z","iopub.execute_input":"2024-04-01T14:10:47.849422Z","iopub.status.idle":"2024-04-01T14:10:48.631677Z","shell.execute_reply.started":"2024-04-01T14:10:47.849387Z","shell.execute_reply":"2024-04-01T14:10:48.630397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import confusion_matrix\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\ncm = confusion_matrix(y_test, prediction)\nplt.figure(figsize=(8, 6))\nsns.heatmap(cm, annot=True, cmap='Blues', fmt='g',xticklabels=knn.classes_, yticklabels=knn.classes_)\nplt.title('Confusion Matrix')\nplt.xlabel('Predicted Labels')\nplt.ylabel('True Labels')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:48.633382Z","iopub.execute_input":"2024-04-01T14:10:48.633890Z","iopub.status.idle":"2024-04-01T14:10:48.960585Z","shell.execute_reply.started":"2024-04-01T14:10:48.633852Z","shell.execute_reply":"2024-04-01T14:10:48.958918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.tree import DecisionTreeClassifier","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:10:48.962925Z","iopub.execute_input":"2024-04-01T14:10:48.963325Z","iopub.status.idle":"2024-04-01T14:10:48.967602Z","shell.execute_reply.started":"2024-04-01T14:10:48.963274Z","shell.execute_reply":"2024-04-01T14:10:48.966612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = train_data[['eeg_label_offset_seconds', 'spectrogram_label_offset_seconds', 'lpd_vote', 'gpd_vote', 'lrda_vote', 'grda_vote']]\ny = train_data['expert_consensus']","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:15:15.562294Z","iopub.execute_input":"2024-04-01T14:15:15.562726Z","iopub.status.idle":"2024-04-01T14:15:15.569954Z","shell.execute_reply.started":"2024-04-01T14:15:15.562694Z","shell.execute_reply":"2024-04-01T14:15:15.568317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train,X_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=42)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:15:16.051343Z","iopub.execute_input":"2024-04-01T14:15:16.051780Z","iopub.status.idle":"2024-04-01T14:15:16.069422Z","shell.execute_reply.started":"2024-04-01T14:15:16.051744Z","shell.execute_reply":"2024-04-01T14:15:16.068336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dtc=DecisionTreeClassifier()","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:15:16.130824Z","iopub.execute_input":"2024-04-01T14:15:16.131238Z","iopub.status.idle":"2024-04-01T14:15:16.135583Z","shell.execute_reply.started":"2024-04-01T14:15:16.131206Z","shell.execute_reply":"2024-04-01T14:15:16.134351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import cross_val_score\nscores = cross_val_score(dtc, X_train, y_train, cv=5)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:15:16.214252Z","iopub.execute_input":"2024-04-01T14:15:16.214746Z","iopub.status.idle":"2024-04-01T14:15:17.233262Z","shell.execute_reply.started":"2024-04-01T14:15:16.214706Z","shell.execute_reply":"2024-04-01T14:15:17.231860Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dtc.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:15:17.235537Z","iopub.execute_input":"2024-04-01T14:15:17.235956Z","iopub.status.idle":"2024-04-01T14:15:17.514436Z","shell.execute_reply.started":"2024-04-01T14:15:17.235918Z","shell.execute_reply":"2024-04-01T14:15:17.513573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction=dtc.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:15:17.516042Z","iopub.execute_input":"2024-04-01T14:15:17.516476Z","iopub.status.idle":"2024-04-01T14:15:17.527672Z","shell.execute_reply.started":"2024-04-01T14:15:17.516444Z","shell.execute_reply":"2024-04-01T14:15:17.526339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\naccuracy = dtc.score(X_test, y_test)\nprint(\"Accuracy:\", accuracy)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:15:17.529985Z","iopub.execute_input":"2024-04-01T14:15:17.530494Z","iopub.status.idle":"2024-04-01T14:15:17.547800Z","shell.execute_reply.started":"2024-04-01T14:15:17.530453Z","shell.execute_reply":"2024-04-01T14:15:17.546097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport tqdm\nfrom sklearn.ensemble import RandomForestClassifier","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:15:17.549540Z","iopub.execute_input":"2024-04-01T14:15:17.550615Z","iopub.status.idle":"2024-04-01T14:15:17.556748Z","shell.execute_reply.started":"2024-04-01T14:15:17.550554Z","shell.execute_reply":"2024-04-01T14:15:17.555333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PDIR = '/kaggle/input/hms-harmful-brain-activity-classification'","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:15:17.558530Z","iopub.execute_input":"2024-04-01T14:15:17.559119Z","iopub.status.idle":"2024-04-01T14:15:17.568108Z","shell.execute_reply.started":"2024-04-01T14:15:17.559081Z","shell.execute_reply":"2024-04-01T14:15:17.566914Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(os.path.join(PDIR, 'train.csv'))\ntrain_data = pd.read_csv('/kaggle/input/hms-harmful-brain-activity-classification/train.csv')\ndisplay(df.head())","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:15:17.570197Z","iopub.execute_input":"2024-04-01T14:15:17.570562Z","iopub.status.idle":"2024-04-01T14:15:17.856247Z","shell.execute_reply.started":"2024-04-01T14:15:17.570528Z","shell.execute_reply":"2024-04-01T14:15:17.855106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"p = train_data[['eeg_label_offset_seconds', 'spectrogram_label_offset_seconds', 'lpd_vote', 'gpd_vote', 'lrda_vote', 'grda_vote']]\nq = train_data['expert_consensus']","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:15:18.972549Z","iopub.execute_input":"2024-04-01T14:15:18.973277Z","iopub.status.idle":"2024-04-01T14:15:18.982245Z","shell.execute_reply.started":"2024-04-01T14:15:18.973232Z","shell.execute_reply":"2024-04-01T14:15:18.980780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(p,q, test_size=0.2, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:26:51.963910Z","iopub.execute_input":"2024-04-01T14:26:51.964359Z","iopub.status.idle":"2024-04-01T14:26:51.992058Z","shell.execute_reply.started":"2024-04-01T14:26:51.964316Z","shell.execute_reply":"2024-04-01T14:26:51.990570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf=RandomForestClassifier()","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:26:52.905213Z","iopub.execute_input":"2024-04-01T14:26:52.906239Z","iopub.status.idle":"2024-04-01T14:26:52.910603Z","shell.execute_reply.started":"2024-04-01T14:26:52.906206Z","shell.execute_reply":"2024-04-01T14:26:52.909336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import cross_val_score\ntry:\n  scores = cross_val_score(rf, X_train, y_train, cv=5)\nexcept KeyboardInterrupt:\n  print(\"Training interrupted by user.\")\n","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:26:53.684881Z","iopub.execute_input":"2024-04-01T14:26:53.685323Z","iopub.status.idle":"2024-04-01T14:27:32.179784Z","shell.execute_reply.started":"2024-04-01T14:26:53.685266Z","shell.execute_reply":"2024-04-01T14:27:32.178274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:27:32.181579Z","iopub.execute_input":"2024-04-01T14:27:32.181869Z","iopub.status.idle":"2024-04-01T14:27:41.174043Z","shell.execute_reply.started":"2024-04-01T14:27:32.181845Z","shell.execute_reply":"2024-04-01T14:27:41.172674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print (f'Train Accuracy - : {rf.score(X_train,y_train):.3f}')\nprint (f'Test Accuracy - : {rf.score(X_test,y_test):.3f}')","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:27:41.175566Z","iopub.execute_input":"2024-04-01T14:27:41.176136Z","iopub.status.idle":"2024-04-01T14:27:43.174535Z","shell.execute_reply.started":"2024-04-01T14:27:41.176104Z","shell.execute_reply":"2024-04-01T14:27:43.173015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sampling_frequency = 200 \ndata_collection_duration = 50\ntotal_samples = sampling_frequency * data_collection_duration \n\n\nnum_train_data_points = 500  \n\n\ntraining_data_df = pd.DataFrame()\n\nfor i in tqdm.tqdm(range(num_train_data_points)):\n    # Loading EEG data for a specified eeg_id\n    eeg_id = df.loc[i, 'eeg_id']\n    eeg_data = pd.read_parquet(os.path.join(PDIR, 'train_eegs', f'{eeg_id}.parquet'))\n    \n    # Extracting EEG data from the Cz electrode for 50 seconds\n    label_offset_time = df.loc[i, 'eeg_label_offset_seconds']  # Offset time for the EEG label\n    label_offset_index = int(sampling_frequency * label_offset_time)  # Calculating offset index\n    cz_electrode_data = eeg_data['Cz'][label_offset_index:label_offset_index + total_samples]  # Extracting data for Cz electrode\n    \n    # Adding the extracted data as a row to the training DataFrame\n    training_data_df = pd.concat([training_data_df, cz_electrode_data.reset_index(drop=True).to_frame().transpose()], axis=0)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:48:15.552081Z","iopub.execute_input":"2024-04-01T14:48:15.552454Z","iopub.status.idle":"2024-04-01T14:48:23.703397Z","shell.execute_reply.started":"2024-04-01T14:48:15.552423Z","shell.execute_reply":"2024-04-01T14:48:23.702553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data_df['expert_consensus'] = df[:num_train_data_points]['expert_consensus'].values\n\n# Removing rows with missing values\ntraining_data_df = training_data_df.dropna()\ntraining_data_df = training_data_df.reset_index(drop=True)\n\n# Separating data into features and target\ny_train = training_data_df['expert_consensus']\nX_train = training_data_df.drop('expert_consensus', axis=1)\n\n# Displaying the first few rows of the feature  dataset\ndisplay(X_train.head())","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:49:14.978973Z","iopub.execute_input":"2024-04-01T14:49:14.979403Z","iopub.status.idle":"2024-04-01T14:49:15.039726Z","shell.execute_reply.started":"2024-04-01T14:49:14.979370Z","shell.execute_reply":"2024-04-01T14:49:15.037896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"forest = RandomForestClassifier(random_state=0)\nforest.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:49:39.246476Z","iopub.execute_input":"2024-04-01T14:49:39.246905Z","iopub.status.idle":"2024-04-01T14:49:41.556518Z","shell.execute_reply.started":"2024-04-01T14:49:39.246871Z","shell.execute_reply":"2024-04-01T14:49:41.555646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import cross_val_score\nscores = cross_val_score(forest, X_train, y_train, cv=5)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:50:09.773905Z","iopub.execute_input":"2024-04-01T14:50:09.774575Z","iopub.status.idle":"2024-04-01T14:50:19.167116Z","shell.execute_reply.started":"2024-04-01T14:50:09.774533Z","shell.execute_reply":"2024-04-01T14:50:19.166072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_csv(os.path.join(PDIR, 'test.csv'))\n\n# Displaying the first few rows of the DataFrame\ndisplay(df_test.head())\n","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:50:44.528961Z","iopub.execute_input":"2024-04-01T14:50:44.529429Z","iopub.status.idle":"2024-04-01T14:50:44.544271Z","shell.execute_reply.started":"2024-04-01T14:50:44.529396Z","shell.execute_reply":"2024-04-01T14:50:44.542586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = pd.DataFrame()\n\n# Iterating over each test data point\nfor i in tqdm.tqdm(range(len(df_test))):\n    # Loading EEG data for a specified eeg_id\n    eeg_id_ = df_test.loc[i, 'eeg_id']\n    tmp = pd.read_parquet(os.path.join(PDIR, 'test_eegs', f'{eeg_id_}.parquet'))\n    \n    # Extracting EEG data from the Cz electrode\n    cz_electrode_data = tmp['Cz']\n    \n    # Adding the extracted data as a row to the testing DataFrame\n    X_test = pd.concat([X_test, cz_electrode_data.reset_index(drop=True).to_frame().transpose()], axis=0)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:51:00.015510Z","iopub.execute_input":"2024-04-01T14:51:00.016490Z","iopub.status.idle":"2024-04-01T14:51:00.050480Z","shell.execute_reply.started":"2024-04-01T14:51:00.016424Z","shell.execute_reply":"2024-04-01T14:51:00.049694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = forest.predict_proba(X_test)\n\n# Read the sample submission file\nsubmission = pd.read_csv(f'{PDIR}/sample_submission.csv')\n\n# Iterate over each test data point\nfor i in tqdm.tqdm(range(len(df_test))):\n    # Set the 'eeg_id' in the submission DataFrame\n    submission.loc[i, 'eeg_id'] = df_test.loc[i, 'eeg_id']\n    \n    # Set the probability for each class in the submission DataFrame\n    for j, cls_name in enumerate(forest.classes_):\n        submission.loc[i, f'{cls_name.lower()}_vote'] = predictions[i, j]","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:51:09.371591Z","iopub.execute_input":"2024-04-01T14:51:09.372749Z","iopub.status.idle":"2024-04-01T14:51:09.476133Z","shell.execute_reply.started":"2024-04-01T14:51:09.372714Z","shell.execute_reply":"2024-04-01T14:51:09.474460Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-04-01T14:52:41.733342Z","iopub.execute_input":"2024-04-01T14:52:41.733742Z","iopub.status.idle":"2024-04-01T14:52:41.739556Z","shell.execute_reply.started":"2024-04-01T14:52:41.733710Z","shell.execute_reply":"2024-04-01T14:52:41.738526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}