{"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"},{"sourceId":7746366,"sourceType":"datasetVersion","datasetId":4528349},{"sourceId":7746394,"sourceType":"datasetVersion","datasetId":4528368}],"isInternetEnabled":false,"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\nimport numpy as np\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\nimport keras\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-03-04T19:17:38.711829Z","iopub.execute_input":"2024-03-04T19:17:38.712241Z","iopub.status.idle":"2024-03-04T19:17:54.438241Z","shell.execute_reply.started":"2024-03-04T19:17:38.712203Z","shell.execute_reply":"2024-03-04T19:17:54.436946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfrom numpy import pi\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport pywt\n\nfrom sklearn.neighbors import NearestNeighbors\nfrom scipy.special import gamma,psi","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:17:54.439991Z","iopub.execute_input":"2024-03-04T19:17:54.440609Z","iopub.status.idle":"2024-03-04T19:17:55.464617Z","shell.execute_reply.started":"2024-03-04T19:17:54.440575Z","shell.execute_reply":"2024-03-04T19:17:55.462984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#!pip install pyentrp\n#from pyentrp import entropy as ent\n#!pip download pyentrp -d ./pyentrp/\n # linear algebra\nimport os\n\n!pwd\n\n!cd /kaggle/input/packages2\n!pwd\n!pip install pyentrp --no-index --find-links=file:///kaggle/input/packages2/\nfrom pyentrp import entropy as ent","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:17:55.466739Z","iopub.execute_input":"2024-03-04T19:17:55.467733Z","iopub.status.idle":"2024-03-04T19:18:15.529314Z","shell.execute_reply.started":"2024-03-04T19:17:55.467694Z","shell.execute_reply":"2024-03-04T19:18:15.527345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv('/kaggle/input/hms-harmful-brain-activity-classification/train.csv')\n","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:15.533791Z","iopub.execute_input":"2024-03-04T19:18:15.534326Z","iopub.status.idle":"2024-03-04T19:18:15.869038Z","shell.execute_reply.started":"2024-03-04T19:18:15.534278Z","shell.execute_reply":"2024-03-04T19:18:15.867213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"files = os.listdir('/kaggle/input/hms-harmful-brain-activity-classification/train_eegs')","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:15.870915Z","iopub.execute_input":"2024-03-04T19:18:15.871769Z","iopub.status.idle":"2024-03-04T19:18:16.282514Z","shell.execute_reply.started":"2024-03-04T19:18:15.871720Z","shell.execute_reply":"2024-03-04T19:18:16.281299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(files)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:16.283925Z","iopub.execute_input":"2024-03-04T19:18:16.284266Z","iopub.status.idle":"2024-03-04T19:18:16.297178Z","shell.execute_reply.started":"2024-03-04T19:18:16.284238Z","shell.execute_reply":"2024-03-04T19:18:16.295919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.info()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:16.298878Z","iopub.execute_input":"2024-03-04T19:18:16.300328Z","iopub.status.idle":"2024-03-04T19:18:16.353527Z","shell.execute_reply.started":"2024-03-04T19:18:16.300282Z","shell.execute_reply":"2024-03-04T19:18:16.352394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:16.355773Z","iopub.execute_input":"2024-03-04T19:18:16.356697Z","iopub.status.idle":"2024-03-04T19:18:16.387150Z","shell.execute_reply.started":"2024-03-04T19:18:16.356622Z","shell.execute_reply":"2024-03-04T19:18:16.385738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_parquet('/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/1000913311.parquet')\ntest= pd.read_parquet('/kaggle/input/hms-harmful-brain-activity-classification/test_eegs/3911565283.parquet')","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:16.389050Z","iopub.execute_input":"2024-03-04T19:18:16.389948Z","iopub.status.idle":"2024-03-04T19:18:16.632258Z","shell.execute_reply.started":"2024-03-04T19:18:16.389903Z","shell.execute_reply":"2024-03-04T19:18:16.630924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train),len(test)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:16.636887Z","iopub.execute_input":"2024-03-04T19:18:16.637316Z","iopub.status.idle":"2024-03-04T19:18:16.646374Z","shell.execute_reply.started":"2024-03-04T19:18:16.637281Z","shell.execute_reply":"2024-03-04T19:18:16.645064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df_train),len(df_train['label_id'].unique())","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:16.648442Z","iopub.execute_input":"2024-03-04T19:18:16.648943Z","iopub.status.idle":"2024-03-04T19:18:16.664680Z","shell.execute_reply.started":"2024-03-04T19:18:16.648910Z","shell.execute_reply":"2024-03-04T19:18:16.663722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train['expert_consensus'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:16.666390Z","iopub.execute_input":"2024-03-04T19:18:16.667108Z","iopub.status.idle":"2024-03-04T19:18:16.685991Z","shell.execute_reply.started":"2024-03-04T19:18:16.667072Z","shell.execute_reply":"2024-03-04T19:18:16.684742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"length of dataframe --- \",len(df_train))\nprint(\"length of expert_consensus --- \",df_train['expert_consensus'].count())\n\ndf_train.expert_consensus.value_counts().plot(kind = 'bar')\n### note each class do not have exactly equal no of cases ,\n### so we will try to filter out bias by taking equal amount of sample in every class","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:16.687651Z","iopub.execute_input":"2024-03-04T19:18:16.688032Z","iopub.status.idle":"2024-03-04T19:18:17.068861Z","shell.execute_reply.started":"2024-03-04T19:18:16.688000Z","shell.execute_reply":"2024-03-04T19:18:17.067543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" df_train.groupby(['expert_consensus']).size()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:17.070507Z","iopub.execute_input":"2024-03-04T19:18:17.072753Z","iopub.status.idle":"2024-03-04T19:18:17.093854Z","shell.execute_reply.started":"2024-03-04T19:18:17.072712Z","shell.execute_reply":"2024-03-04T19:18:17.092198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train\n","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:17.096519Z","iopub.execute_input":"2024-03-04T19:18:17.096921Z","iopub.status.idle":"2024-03-04T19:18:17.123668Z","shell.execute_reply.started":"2024-03-04T19:18:17.096888Z","shell.execute_reply":"2024-03-04T19:18:17.122293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## no of parquet files associated with patient id\nx = df_train['patient_id'].value_counts()\n","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:17.125105Z","iopub.execute_input":"2024-03-04T19:18:17.125547Z","iopub.status.idle":"2024-03-04T19:18:17.138135Z","shell.execute_reply.started":"2024-03-04T19:18:17.125515Z","shell.execute_reply":"2024-03-04T19:18:17.136578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# trying to find no of samples under each ccategory for every  patient \ndf_train.groupby(['patient_id', 'expert_consensus']).size()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:17.139775Z","iopub.execute_input":"2024-03-04T19:18:17.140181Z","iopub.status.idle":"2024-03-04T19:18:17.171104Z","shell.execute_reply.started":"2024-03-04T19:18:17.140148Z","shell.execute_reply":"2024-03-04T19:18:17.169921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"samp_df = df_train.groupby([\"patient_id\",\"expert_consensus\"]).size()\nsamp_df.to_excel(\"patient_expert_consensus.xlsx\")","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:17.173840Z","iopub.execute_input":"2024-03-04T19:18:17.174304Z","iopub.status.idle":"2024-03-04T19:18:20.747522Z","shell.execute_reply.started":"2024-03-04T19:18:17.174263Z","shell.execute_reply":"2024-03-04T19:18:20.746302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ndef s_entropy(freq_list):\n    ''' This function computes the shannon entropy of a given frequency distribution.\n    USAGE: shannon_entropy(freq_list)\n    ARGS: freq_list = Numeric vector representing the frequency distribution\n    OUTPUT: A numeric value representing shannon's entropy'''\n    freq_list = [element for element in freq_list if element != 0]\n    sh_entropy = 0.0\n    for freq in freq_list:\n        sh_entropy += freq * np.log(freq)\n    sh_entropy = -sh_entropy\n    return(sh_entropy)\n\ndef p_entropy(op):\n    ordinal_pat = op\n    max_entropy = np.log(len(ordinal_pat))\n    p = np.divide(np.array(ordinal_pat), float(sum(ordinal_pat)))\n    return(s_entropy(p)/max_entropy)\n","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:20.749264Z","iopub.execute_input":"2024-03-04T19:18:20.750363Z","iopub.status.idle":"2024-03-04T19:18:20.761129Z","shell.execute_reply.started":"2024-03-04T19:18:20.750317Z","shell.execute_reply":"2024-03-04T19:18:20.759940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def renyi_entropy(data, alpha):\n    \n    _, ele_counts = np.unique( np.around(data, decimals = 0 ), return_counts = True )\n    summation = np.sum( np.log( ( ele_counts / len(data)) ** alpha ) ) \n    reny_ent = (1 / (1 - alpha)) * summation\n    return np.array(reny_ent)\n\ndef permutation_ent(data, order=2):\n    if order < 2:\n        order = 2\n    \n    data = np.around(data, decimals = 0)\n    perm_ent = ent.permutation_entropy(data, order = order, normalize = True)\n    return np.array(perm_ent)\n\ndef tsallis_ent(data, alpha):\n    _, ele_counts = np.unique( np.around(data, decimals = 0 ), return_counts = True )\n    summation = np.sum( np.log( ( ele_counts / len(data)) ** alpha ) ) \n    tsa_ent =  (1 / (alpha - 1)) * ( 1 - summation) \n    return np.array(tsa_ent)\n\ndef kraskov_ent(data, k):\n    #if k < 1:\n        #k = 1\n    \n    #k=int(k)\n    knn = NearestNeighbors(n_neighbors=k)\n    X = np.around(data, decimals = 0 ).reshape(-1,1)\n    knn.fit(X)\n    r, _ = knn.kneighbors(X)\n    n, d = X.shape\n    volume_unit_ball = (pi**(.5*d)) / gamma(.5*d + 1)    \n    kra_ent = (d*np.mean(np.log(r[:,-1] + np.finfo(X.dtype).eps))+ np.log(volume_unit_ball)\n               + psi(n) - psi(k))\n    return np.array(kra_ent)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:20.762541Z","iopub.execute_input":"2024-03-04T19:18:20.763295Z","iopub.status.idle":"2024-03-04T19:18:20.778044Z","shell.execute_reply.started":"2024-03-04T19:18:20.763258Z","shell.execute_reply":"2024-03-04T19:18:20.776864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def DWT(data,wavelet_family = 'db10', level = 4):\n\n    #data = np.load(\"../Healthcare_signal_processing/Datasets/Bonn/data_all.npz\")\n    db = pywt.Wavelet(wavelet_family)\n  \n    cA4, cD4, cD3, cD2, cD1 = pywt.wavedec(data, db, level = level)\n    #print(samp.shape,len(cA4),len(cD4),len(d3),len(d2),len(d1))\n\n    return [cA4, cD4, cD3, cD2, cD1]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:20.779980Z","iopub.execute_input":"2024-03-04T19:18:20.780419Z","iopub.status.idle":"2024-03-04T19:18:20.796483Z","shell.execute_reply.started":"2024-03-04T19:18:20.780386Z","shell.execute_reply":"2024-03-04T19:18:20.795536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\ngroups = [0, 1, 2, 3,4]\ncolumns=['A - A4','A - D4','A - D3','A - D2','A - D1']\nX_train = pd.read_parquet('/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/1000913311.parquet')\nfor sig in X_train.columns:\n    sig_DWT = DWT(X_train[sig])\n    i = 1 \n    plt.figure(figsize=(20,10))\n    plt.title(sig,loc='center')\n    for group in groups:\n        plt.subplot(len(groups), 1, i)\n        \n        plt.plot(sig_DWT[group])\n        plt.title(sig+' -- '+columns[group], y=0.5, loc='right')\n        i += 1\n\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:20.797982Z","iopub.execute_input":"2024-03-04T19:18:20.798353Z","iopub.status.idle":"2024-03-04T19:18:41.718402Z","shell.execute_reply.started":"2024-03-04T19:18:20.798315Z","shell.execute_reply":"2024-03-04T19:18:41.716961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def extract_enctropy_features (signal,re_alpha =2 ,pe_order=2,tsa_order=3,kras_order=3):\n    decomp_wavelet = DWT(signal) ## DWT will decompose the signal into 5 coefficients \n    features=[]\n    for coeff in decomp_wavelet:\n        features.append(renyi_entropy(coeff,re_alpha))\n        features.append(permutation_ent(coeff,pe_order))\n        features.append(tsallis_ent(coeff,tsa_order))\n        #features.append(kraskov_ent(coeff,kras_order))\n    ## after finiding enrtropies for each coefficeint  we get 20 features - \n    return features","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:41.719722Z","iopub.execute_input":"2024-03-04T19:18:41.720060Z","iopub.status.idle":"2024-03-04T19:18:41.727700Z","shell.execute_reply.started":"2024-03-04T19:18:41.720032Z","shell.execute_reply":"2024-03-04T19:18:41.726323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## considering equal number of smaples in each case == 14000\n\"\"\"\nexpert_consensus\nGPD        16702\nGRDA       18861\nLPD        14856\nLRDA       16640\nOther      18808\nSeizure    20933\n\"\"\"\nclasses = ['GPD','GRDA','LPD','LPDA','Other','Seizure']\ninput_X = []\ntarget_values = []\ndf_train_GPD = df_train[df_train['expert_consensus'] == 'GPD']\ndf_train_GRDA = df_train[df_train['expert_consensus'] == 'GRDA']\ndf_train_LPD = df_train[df_train['expert_consensus'] == 'LPD']\ndf_train_LRDA = df_train[df_train['expert_consensus'] == 'LRDA']\ndf_train_Other = df_train[df_train['expert_consensus'] == 'Other']\ndf_train_Seizure = df_train[df_train['expert_consensus'] == 'Seizure']","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:41.729092Z","iopub.execute_input":"2024-03-04T19:18:41.729663Z","iopub.status.idle":"2024-03-04T19:18:41.876747Z","shell.execute_reply.started":"2024-03-04T19:18:41.729618Z","shell.execute_reply":"2024-03-04T19:18:41.875274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train_GPD","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:41.878334Z","iopub.execute_input":"2024-03-04T19:18:41.878735Z","iopub.status.idle":"2024-03-04T19:18:41.904534Z","shell.execute_reply.started":"2024-03-04T19:18:41.878701Z","shell.execute_reply":"2024-03-04T19:18:41.902738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eeg_ids= df_train['eeg_id'].unique()\nd = {}\nfor eeg_id in eeg_ids:\n    lab = df_train[df_train['eeg_id'] == eeg_id]['expert_consensus'].values\n    if all(lab):\n        if lab[0] not in d.keys():\n            d[lab[0]] = [eeg_id]\n        else:\n            d[lab[0]].append(eeg_id)\nfor  key,val in d.items():\n    print('class ->',key ,'no of eegs file which are completely mapped to a single label',str(len(val)))","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:18:41.905783Z","iopub.execute_input":"2024-03-04T19:18:41.906121Z","iopub.status.idle":"2024-03-04T19:18:50.901714Z","shell.execute_reply.started":"2024-03-04T19:18:41.906093Z","shell.execute_reply":"2024-03-04T19:18:50.900413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n'''\nfin_labels = labels[np.random.choice(len(labels), size=900, replace=False)]\nfor label_id in fin_labels:\n    temp=[]\n    target_values.append(df_train_gpd[df_train_gpd['eeg_id'] == label_id][['seizure_vote','lpd_vote','gpd_vote','lrda_vote','grda_vote','other_vote']].values)\n    #sig_df= pd.read_parquet(\"/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/{label_id}.parquet\".format(label_id = label_id))\n    for col in sig_df.columns:\n        temp.extend(extract_enctropy_features(sig_df[col].values))\nprint(temp)\n'''\n","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:19:16.434608Z","iopub.execute_input":"2024-03-04T19:19:16.435044Z","iopub.status.idle":"2024-03-04T19:19:16.443117Z","shell.execute_reply.started":"2024-03-04T19:19:16.435011Z","shell.execute_reply":"2024-03-04T19:19:16.441939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_eeg = []\nvote = []\n","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:29:07.907417Z","iopub.execute_input":"2024-03-04T19:29:07.907907Z","iopub.status.idle":"2024-03-04T19:29:07.913923Z","shell.execute_reply.started":"2024-03-04T19:29:07.907873Z","shell.execute_reply":"2024-03-04T19:29:07.912147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = df_train_Seizure.sort_values('seizure_vote', ascending=False).reset_index()\ni, count=0, 0\npatient_li=[]\nwhile count<100:\n    pat_id = sample['patient_id'][i]\n    if pat_id in patient_li:\n        i+=1\n        continue\n    patient_li.append(pat_id)\n    eeg_id = sample['eeg_id'][i]\n    offset_idx = int(sample['eeg_label_offset_seconds'][i]*100)\n    eeg = pd.read_parquet(f'/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/{eeg_id}.parquet')\n    eeg = eeg[offset_idx:offset_idx+5000]\n    temp = []\n    for col in eeg.columns:\n        if all(np.isnan(eeg[col])) :\n            print(eeg.eeg_id.unique())\n        temp.extend(extract_enctropy_features(eeg[col].values))\n    input_eeg.append(temp)\n    vote.append(sample[['seizure_vote' ,'lpd_vote' ,'gpd_vote', 'lrda_vote', 'grda_vote' ,'other_vote']].iloc[i].values)\n\n    count+=1\n    i+=1","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:29:08.372886Z","iopub.execute_input":"2024-03-04T19:29:08.373262Z","iopub.status.idle":"2024-03-04T19:29:15.789105Z","shell.execute_reply.started":"2024-03-04T19:29:08.373233Z","shell.execute_reply":"2024-03-04T19:29:15.787886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(vote),len(input_eeg)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:29:15.791473Z","iopub.execute_input":"2024-03-04T19:29:15.791850Z","iopub.status.idle":"2024-03-04T19:29:15.801261Z","shell.execute_reply.started":"2024-03-04T19:29:15.791820Z","shell.execute_reply":"2024-03-04T19:29:15.799767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(input_eeg[0])","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:29:15.803434Z","iopub.execute_input":"2024-03-04T19:29:15.803968Z","iopub.status.idle":"2024-03-04T19:29:15.812271Z","shell.execute_reply.started":"2024-03-04T19:29:15.803927Z","shell.execute_reply":"2024-03-04T19:29:15.810974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = df_train_GPD.sort_values('gpd_vote', ascending=False).reset_index()\ni, count=0, 0\npatient_li=[]\nwhile count<100:\n    pat_id = sample['patient_id'][i]\n    if pat_id in patient_li:\n        i+=1\n        continue\n    patient_li.append(pat_id)\n    eeg_id = sample['eeg_id'][i]\n    offset_idx = int(sample['eeg_label_offset_seconds'][i]*100)\n    eeg = pd.read_parquet(f'/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/{eeg_id}.parquet')\n    eeg = eeg[offset_idx:offset_idx+5000]\n    temp = []\n    for col in eeg.columns:\n        if all(np.isnan(eeg[col])) :\n            print(eeg.eeg_id.unique())\n        temp.extend(extract_enctropy_features(eeg[col].values))\n    input_eeg.append(temp)\n    vote.append(sample[['seizure_vote' ,'lpd_vote' ,'gpd_vote', 'lrda_vote', 'grda_vote' ,'other_vote']].iloc[i].values)\n    \n    count+=1\n    i+=1","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:29:15.814511Z","iopub.execute_input":"2024-03-04T19:29:15.814887Z","iopub.status.idle":"2024-03-04T19:29:23.259807Z","shell.execute_reply.started":"2024-03-04T19:29:15.814856Z","shell.execute_reply":"2024-03-04T19:29:23.258610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(vote)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:29:23.261581Z","iopub.execute_input":"2024-03-04T19:29:23.262204Z","iopub.status.idle":"2024-03-04T19:29:23.272313Z","shell.execute_reply.started":"2024-03-04T19:29:23.262156Z","shell.execute_reply":"2024-03-04T19:29:23.270580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = df_train_GRDA.sort_values('grda_vote', ascending=False).reset_index()\ni, count=0, 0\npatient_li=[]\nwhile count<100:\n    pat_id = sample['patient_id'][i]\n    if pat_id in patient_li:\n        i+=1\n        continue\n    patient_li.append(pat_id)\n    eeg_id = sample['eeg_id'][i]\n    offset_idx = int(sample['eeg_label_offset_seconds'][i]*100)\n    eeg = pd.read_parquet(f'/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/{eeg_id}.parquet')\n    eeg = eeg[offset_idx:offset_idx+5000]\n    temp = []\n    for col in eeg.columns:\n        if all(np.isnan(eeg[col])) :\n            print(eeg.eeg_id.unique())\n        temp.extend(extract_enctropy_features(eeg[col].values))\n    input_eeg.append(temp)\n    vote.append(sample[['seizure_vote' ,'lpd_vote' ,'gpd_vote', 'lrda_vote', 'grda_vote' ,'other_vote']].iloc[i].values)\n    \n    count+=1\n    i+=1","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:29:23.626015Z","iopub.execute_input":"2024-03-04T19:29:23.626438Z","iopub.status.idle":"2024-03-04T19:29:31.023804Z","shell.execute_reply.started":"2024-03-04T19:29:23.626405Z","shell.execute_reply":"2024-03-04T19:29:31.022159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(vote)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:29:31.026271Z","iopub.execute_input":"2024-03-04T19:29:31.026755Z","iopub.status.idle":"2024-03-04T19:29:31.037766Z","shell.execute_reply.started":"2024-03-04T19:29:31.026710Z","shell.execute_reply":"2024-03-04T19:29:31.036248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = df_train_LPD.sort_values('lpd_vote', ascending=False).reset_index()\ni, count=0, 0\npatient_li=[]\nwhile count<100:\n    pat_id = sample['patient_id'][i]\n    if pat_id in patient_li:\n        i+=1\n        continue\n    patient_li.append(pat_id)\n    eeg_id = sample['eeg_id'][i]\n    offset_idx = int(sample['eeg_label_offset_seconds'][i]*100)\n    eeg = pd.read_parquet(f'/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/{eeg_id}.parquet')\n    eeg = eeg[offset_idx:offset_idx+5000]\n    temp = []\n    for col in eeg.columns:\n        if all(np.isnan(eeg[col])) :\n            print(eeg.eeg_id.unique())\n        temp.extend(extract_enctropy_features(eeg[col].values))\n    input_eeg.append(temp)\n    vote.append(sample[['seizure_vote' ,'lpd_vote' ,'gpd_vote', 'lrda_vote', 'grda_vote' ,'other_vote']].iloc[i].values)\n    \n    count+=1\n    i+=1","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:29:36.834610Z","iopub.execute_input":"2024-03-04T19:29:36.835175Z","iopub.status.idle":"2024-03-04T19:29:44.101395Z","shell.execute_reply.started":"2024-03-04T19:29:36.835132Z","shell.execute_reply":"2024-03-04T19:29:44.100118Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(vote)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:29:45.506517Z","iopub.execute_input":"2024-03-04T19:29:45.507261Z","iopub.status.idle":"2024-03-04T19:29:45.514943Z","shell.execute_reply.started":"2024-03-04T19:29:45.507217Z","shell.execute_reply":"2024-03-04T19:29:45.513665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = df_train_LRDA.sort_values('lrda_vote', ascending=False).reset_index()\ni, count=0, 0\npatient_li=[]\nwhile count<100:\n    pat_id = sample['patient_id'][i]\n    if pat_id in patient_li:\n        i+=1\n        continue\n    patient_li.append(pat_id)\n    eeg_id = sample['eeg_id'][i]\n    offset_idx = int(sample['eeg_label_offset_seconds'][i]*100)\n    eeg = pd.read_parquet(f'/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/{eeg_id}.parquet')\n    eeg = eeg[offset_idx:offset_idx+5000]\n    temp = []\n    for col in eeg.columns:\n        if all(np.isnan(eeg[col])) :\n            print(eeg.eeg_id.unique())\n        temp.extend(extract_enctropy_features(eeg[col].values))\n    input_eeg.append(temp)\n    vote.append(sample[['seizure_vote' ,'lpd_vote' ,'gpd_vote', 'lrda_vote', 'grda_vote' ,'other_vote']].iloc[i].values)\n\n    count+=1\n    i+=1","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:29:57.361125Z","iopub.execute_input":"2024-03-04T19:29:57.361531Z","iopub.status.idle":"2024-03-04T19:30:05.444140Z","shell.execute_reply.started":"2024-03-04T19:29:57.361500Z","shell.execute_reply":"2024-03-04T19:30:05.442301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(vote)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:30:05.686653Z","iopub.execute_input":"2024-03-04T19:30:05.687229Z","iopub.status.idle":"2024-03-04T19:30:05.695895Z","shell.execute_reply.started":"2024-03-04T19:30:05.687179Z","shell.execute_reply":"2024-03-04T19:30:05.694594Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = df_train_Other.sort_values('other_vote', ascending=False).reset_index()\ni, count=0, 0\npatient_li=[]\nwhile count<100:\n    pat_id = sample['patient_id'][i]\n    if pat_id in patient_li:\n        i+=1\n        continue\n    patient_li.append(pat_id)\n    eeg_id = sample['eeg_id'][i]\n    offset_idx = int(sample['eeg_label_offset_seconds'][i]*100)\n    eeg = pd.read_parquet(f'/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/{eeg_id}.parquet')\n    eeg = eeg[offset_idx:offset_idx+5000]\n    temp = []\n    for col in eeg.columns:\n        if all(np.isnan(eeg[col])) :\n            print(eeg.eeg_id.unique())\n        temp.extend(extract_enctropy_features(eeg[col].values))\n    input_eeg.append(temp)\n    vote.append(sample[['seizure_vote' ,'lpd_vote' ,'gpd_vote', 'lrda_vote', 'grda_vote' ,'other_vote']].iloc[i].values)\n    \n\n    count+=1\n    i+=1","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:30:18.957016Z","iopub.execute_input":"2024-03-04T19:30:18.957525Z","iopub.status.idle":"2024-03-04T19:30:26.314200Z","shell.execute_reply.started":"2024-03-04T19:30:18.957482Z","shell.execute_reply":"2024-03-04T19:30:26.312988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(vote)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:30:26.407095Z","iopub.execute_input":"2024-03-04T19:30:26.407682Z","iopub.status.idle":"2024-03-04T19:30:26.416101Z","shell.execute_reply.started":"2024-03-04T19:30:26.407600Z","shell.execute_reply":"2024-03-04T19:30:26.414710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"###TEST data \ndf_test = pd.read_csv(\"/kaggle/input/hms-harmful-brain-activity-classification/test.csv\")\ndf_test\neeg_test = pd.read_parquet(f'/kaggle/input/hms-harmful-brain-activity-classification/test_eegs/3911565283.parquet')\neeg_test\ntemp_test = []\n\nfor col in eeg_test.columns:\n    if all(np.isnan(eeg_test[col])) :\n        print(eeg_test.eeg_id.unique())\n    temp_test.extend(extract_enctropy_features(eeg_test[col].values))  ","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:21:37.057963Z","iopub.execute_input":"2024-03-04T19:21:37.058349Z","iopub.status.idle":"2024-03-04T19:21:37.165252Z","shell.execute_reply.started":"2024-03-04T19:21:37.058318Z","shell.execute_reply":"2024-03-04T19:21:37.164251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_eeg_test= np.array(temp_test)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:21:37.167006Z","iopub.execute_input":"2024-03-04T19:21:37.167688Z","iopub.status.idle":"2024-03-04T19:21:37.172744Z","shell.execute_reply.started":"2024-03-04T19:21:37.167651Z","shell.execute_reply":"2024-03-04T19:21:37.171548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_eeg_test = input_eeg_test.reshape(1,300)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:21:37.174113Z","iopub.execute_input":"2024-03-04T19:21:37.174469Z","iopub.status.idle":"2024-03-04T19:21:37.185875Z","shell.execute_reply.started":"2024-03-04T19:21:37.174438Z","shell.execute_reply":"2024-03-04T19:21:37.184605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(vote),len(input_eeg)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:21:37.187125Z","iopub.execute_input":"2024-03-04T19:21:37.187459Z","iopub.status.idle":"2024-03-04T19:21:37.200486Z","shell.execute_reply.started":"2024-03-04T19:21:37.187431Z","shell.execute_reply":"2024-03-04T19:21:37.199116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vote = np.array(vote)\ninput_eeg = np.array(input_eeg)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:21:37.201938Z","iopub.execute_input":"2024-03-04T19:21:37.202248Z","iopub.status.idle":"2024-03-04T19:21:37.284060Z","shell.execute_reply.started":"2024-03-04T19:21:37.202222Z","shell.execute_reply":"2024-03-04T19:21:37.282981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vote[0:100]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:25:07.057047Z","iopub.execute_input":"2024-03-04T19:25:07.057615Z","iopub.status.idle":"2024-03-04T19:25:07.069265Z","shell.execute_reply.started":"2024-03-04T19:25:07.057577Z","shell.execute_reply":"2024-03-04T19:25:07.067983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vote[101:200]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:25:17.693804Z","iopub.execute_input":"2024-03-04T19:25:17.694195Z","iopub.status.idle":"2024-03-04T19:25:17.704886Z","shell.execute_reply.started":"2024-03-04T19:25:17.694165Z","shell.execute_reply":"2024-03-04T19:25:17.703695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vote[201:300]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:31:37.465354Z","iopub.execute_input":"2024-03-04T19:31:37.466558Z","iopub.status.idle":"2024-03-04T19:31:37.483427Z","shell.execute_reply.started":"2024-03-04T19:31:37.466509Z","shell.execute_reply":"2024-03-04T19:31:37.482095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vote[301:400]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:25:29.601209Z","iopub.execute_input":"2024-03-04T19:25:29.601622Z","iopub.status.idle":"2024-03-04T19:25:29.613857Z","shell.execute_reply.started":"2024-03-04T19:25:29.601593Z","shell.execute_reply":"2024-03-04T19:25:29.612285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vote[401:500]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:24:43.833890Z","iopub.execute_input":"2024-03-04T19:24:43.834269Z","iopub.status.idle":"2024-03-04T19:24:43.845923Z","shell.execute_reply.started":"2024-03-04T19:24:43.834238Z","shell.execute_reply":"2024-03-04T19:24:43.844565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vote[501:600]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:26:59.925315Z","iopub.execute_input":"2024-03-04T19:26:59.925773Z","iopub.status.idle":"2024-03-04T19:26:59.936779Z","shell.execute_reply.started":"2024-03-04T19:26:59.925740Z","shell.execute_reply":"2024-03-04T19:26:59.935472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vote = np.array(vote)\nmax = vote.max(axis=1).reshape(-1, 1)\n\n# Setting max values as 1 and other as 0\nfinal_vote = np.where(vote == max, 1, 0)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:36:21.034382Z","iopub.execute_input":"2024-03-04T19:36:21.034840Z","iopub.status.idle":"2024-03-04T19:36:21.043504Z","shell.execute_reply.started":"2024-03-04T19:36:21.034796Z","shell.execute_reply":"2024-03-04T19:36:21.042290Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_vote[400:500]","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:18:53.207899Z","iopub.execute_input":"2024-03-04T20:18:53.208272Z","iopub.status.idle":"2024-03-04T20:18:53.221975Z","shell.execute_reply.started":"2024-03-04T20:18:53.208241Z","shell.execute_reply":"2024-03-04T20:18:53.220335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.models import Sequential\nfrom keras.layers import Dense\nfrom sklearn.model_selection import cross_val_score, train_test_split\nfrom sklearn.metrics import accuracy_score","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:37:32.404068Z","iopub.execute_input":"2024-03-04T19:37:32.404536Z","iopub.status.idle":"2024-03-04T19:37:32.410091Z","shell.execute_reply.started":"2024-03-04T19:37:32.404504Z","shell.execute_reply":"2024-03-04T19:37:32.409015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import MinMaxScaler\n\nscaler = MinMaxScaler()\ninput_eeg=scaler.fit_transform(input_eeg)\ninput_eeg_test = scaler.fit_transform(input_eeg_test)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T19:37:32.793195Z","iopub.execute_input":"2024-03-04T19:37:32.793661Z","iopub.status.idle":"2024-03-04T19:37:32.880788Z","shell.execute_reply.started":"2024-03-04T19:37:32.793603Z","shell.execute_reply":"2024-03-04T19:37:32.879454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## the features are extracted and further can be used to train a model\n","metadata":{}},{"cell_type":"code","source":"def ANN(X,Y,input_eeg_test):\n    acc = []\n    models = []\n    predictions = []\n    #ten_fold_score = cross_val_score(classify, X, Y, cv = 10)\n    for _ in range(2):\n        model = Sequential()\n        model.add(Dense(200, input_dim=X.shape[1], activation='relu'))\n        #model.add(Dense(300,input_dim=X.shape[1], activation='relu'))\n        model.add(Dense(150, activation='relu'))\n        model.add(Dense(50, activation='relu'))\n        model.add(Dense(6, activation='softmax'))\n        # Compile model\n        mse = keras.losses.MeanSquaredError(reduction=\"sum_over_batch_size\", name=\"mean_squared_error\")\n        model.compile(loss='categorical_crossentropy', optimizer='adam',metrics = ['accuracy'])\n        # fit the keras model on the dataset\n\n        X_train , X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.15)\n        model.fit(np.array(X_train), np.array(Y_train), epochs=50, batch_size=5, verbose=1)\n        \n        \n        scores = model.evaluate(np.array(X_test),Y_test)\n        for i,m in enumerate(model.metrics_names):\n            print(str(m) +'--'+str(scores[i]))\n        models.append(model)\n        Y_pred = model.predict(np.array(np.array(input_eeg_test)))\n        predictions.append(Y_pred)\n    np.save(\"ANN\", acc)\n    return models,predictions","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:31:48.539775Z","iopub.execute_input":"2024-03-04T20:31:48.541030Z","iopub.status.idle":"2024-03-04T20:31:48.555212Z","shell.execute_reply.started":"2024-03-04T20:31:48.540981Z","shell.execute_reply":"2024-03-04T20:31:48.552993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"final_vote.shape,input_eeg.shape\n","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:31:53.595500Z","iopub.execute_input":"2024-03-04T20:31:53.595954Z","iopub.status.idle":"2024-03-04T20:31:53.604423Z","shell.execute_reply.started":"2024-03-04T20:31:53.595917Z","shell.execute_reply":"2024-03-04T20:31:53.603114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_eeg","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:31:53.846498Z","iopub.execute_input":"2024-03-04T20:31:53.847423Z","iopub.status.idle":"2024-03-04T20:31:53.855507Z","shell.execute_reply.started":"2024-03-04T20:31:53.847385Z","shell.execute_reply":"2024-03-04T20:31:53.854184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" models,preds = ANN(input_eeg,vote,input_eeg_test)","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:31:56.572865Z","iopub.execute_input":"2024-03-04T20:31:56.573255Z","iopub.status.idle":"2024-03-04T20:32:40.038302Z","shell.execute_reply.started":"2024-03-04T20:31:56.573225Z","shell.execute_reply":"2024-03-04T20:32:40.037216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:32:40.040227Z","iopub.execute_input":"2024-03-04T20:32:40.041397Z","iopub.status.idle":"2024-03-04T20:32:40.050884Z","shell.execute_reply.started":"2024-03-04T20:32:40.041345Z","shell.execute_reply":"2024-03-04T20:32:40.049393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df = pd.read_csv('/kaggle/input/hms-harmful-brain-activity-classification/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:32:40.052590Z","iopub.execute_input":"2024-03-04T20:32:40.053606Z","iopub.status.idle":"2024-03-04T20:32:40.068530Z","shell.execute_reply.started":"2024-03-04T20:32:40.053560Z","shell.execute_reply":"2024-03-04T20:32:40.067426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:32:40.071334Z","iopub.execute_input":"2024-03-04T20:32:40.072026Z","iopub.status.idle":"2024-03-04T20:32:40.086591Z","shell.execute_reply.started":"2024-03-04T20:32:40.071973Z","shell.execute_reply":"2024-03-04T20:32:40.085575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"samp = preds","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:32:40.088346Z","iopub.execute_input":"2024-03-04T20:32:40.089487Z","iopub.status.idle":"2024-03-04T20:32:40.099891Z","shell.execute_reply.started":"2024-03-04T20:32:40.089449Z","shell.execute_reply":"2024-03-04T20:32:40.098562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:32:40.101452Z","iopub.execute_input":"2024-03-04T20:32:40.101874Z","iopub.status.idle":"2024-03-04T20:32:40.114322Z","shell.execute_reply.started":"2024-03-04T20:32:40.101831Z","shell.execute_reply":"2024-03-04T20:32:40.112877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sum(preds[0])","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:32:40.115612Z","iopub.execute_input":"2024-03-04T20:32:40.115950Z","iopub.status.idle":"2024-03-04T20:32:40.126882Z","shell.execute_reply.started":"2024-03-04T20:32:40.115922Z","shell.execute_reply":"2024-03-04T20:32:40.125986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output_file = 'output{}.csv'\ncolmns = list(sub_df.columns)\ncolmns.remove('eeg_id')\nprint(colmns)\nfor i in range(len(preds)):\n    pred = preds[i]\n    for j in range(len(colmns)):\n        print(pred.shape,j)\n        sub_df[colmns[j]][0] = pred[0][j]\n        \n    sub_df.to_csv('submission.csv',index = False)\n    ","metadata":{"execution":{"iopub.status.busy":"2024-03-04T20:32:40.128245Z","iopub.execute_input":"2024-03-04T20:32:40.129576Z","iopub.status.idle":"2024-03-04T20:32:40.154608Z","shell.execute_reply.started":"2024-03-04T20:32:40.129542Z","shell.execute_reply":"2024-03-04T20:32:40.153010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}