{"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":30684,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Notes\nDoes not account for EEG subsets; assumes that the first classification seen for a unique EEG ID is the overall harmful brain activity for the entire EEG sample.","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\ntrain_df = pd.read_csv(\"/kaggle/input/hms-harmful-brain-activity-classification/train.csv\").drop_duplicates(\"eeg_id\", keep=\"first\").sort_values(by=[\"eeg_id\"])\ntrain_df.head(10)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-04-25T23:24:46.905972Z","iopub.execute_input":"2024-04-25T23:24:46.906722Z","iopub.status.idle":"2024-04-25T23:24:47.166354Z","shell.execute_reply.started":"2024-04-25T23:24:46.906686Z","shell.execute_reply":"2024-04-25T23:24:47.165236Z"},"trusted":true},"execution_count":14,"outputs":[{"execution_count":14,"output_type":"execute_result","data":{"text/plain":"         eeg_id  eeg_sub_id  eeg_label_offset_seconds  spectrogram_id  \\\n40927    568657           0                       0.0       789577333   \n77116    582999           0                       0.0      1552638400   \n1149     642382           0                       0.0        14960202   \n31929    751790           0                       0.0       618728447   \n3319     778705           0                       0.0        52296320   \n101768  1629671           0                       0.0      2036345030   \n6914    1895581           0                       0.0       128369999   \n16225   2061593           0                       0.0       320962633   \n103823  2078097           0                       0.0      2074135650   \n60929   2366870           0                       0.0      1232582129   \n\n        spectrogram_sub_id  spectrogram_label_offset_seconds    label_id  \\\n40927                    0                               0.0  1825637311   \n77116                    0                               0.0  1722186807   \n1149                    12                            1008.0  3254468733   \n31929                    4                             908.0  2898467035   \n3319                     0                               0.0  3255875127   \n101768                   0                               0.0  3715807879   \n6914                     3                            1138.0  2303400556   \n16225                    3                            1450.0  2716610817   \n103823                  45                            3342.0  4098758075   \n60929                    0                               0.0  2855109799   \n\n        patient_id expert_consensus  seizure_vote  lpd_vote  gpd_vote  \\\n40927        20654            Other             0         0         3   \n77116        20230              LPD             0        12         0   \n1149          5955            Other             0         0         0   \n31929        38549              GPD             0         0         1   \n3319         40955            Other             0         0         0   \n101768       37481          Seizure             3         0         0   \n6914         47999            Other             1         0         0   \n16225        23828            Other             0         0         0   \n103823       61174            Other             0         0         0   \n60929        23633            Other             0         1         0   \n\n        lrda_vote  grda_vote  other_vote  \n40927           0          2           7  \n77116           1          0           1  \n1149            0          0           1  \n31929           0          0           0  \n3319            0          0           2  \n101768          0          0           0  \n6914            0          1          11  \n16225           0          0           1  \n103823          0          0           2  \n60929           0          0           2  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>eeg_id</th>\n      <th>eeg_sub_id</th>\n      <th>eeg_label_offset_seconds</th>\n      <th>spectrogram_id</th>\n      <th>spectrogram_sub_id</th>\n      <th>spectrogram_label_offset_seconds</th>\n      <th>label_id</th>\n      <th>patient_id</th>\n      <th>expert_consensus</th>\n      <th>seizure_vote</th>\n      <th>lpd_vote</th>\n      <th>gpd_vote</th>\n      <th>lrda_vote</th>\n      <th>grda_vote</th>\n      <th>other_vote</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>40927</th>\n      <td>568657</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>789577333</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>1825637311</td>\n      <td>20654</td>\n      <td>Other</td>\n      <td>0</td>\n      <td>0</td>\n      <td>3</td>\n      <td>0</td>\n      <td>2</td>\n      <td>7</td>\n    </tr>\n    <tr>\n      <th>77116</th>\n      <td>582999</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>1552638400</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>1722186807</td>\n      <td>20230</td>\n      <td>LPD</td>\n      <td>0</td>\n      <td>12</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1149</th>\n      <td>642382</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>14960202</td>\n      <td>12</td>\n      <td>1008.0</td>\n      <td>3254468733</td>\n      <td>5955</td>\n      <td>Other</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>31929</th>\n      <td>751790</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>618728447</td>\n      <td>4</td>\n      <td>908.0</td>\n      <td>2898467035</td>\n      <td>38549</td>\n      <td>GPD</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>3319</th>\n      <td>778705</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>52296320</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>3255875127</td>\n      <td>40955</td>\n      <td>Other</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>101768</th>\n      <td>1629671</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>2036345030</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>3715807879</td>\n      <td>37481</td>\n      <td>Seizure</td>\n      <td>3</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>6914</th>\n      <td>1895581</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>128369999</td>\n      <td>3</td>\n      <td>1138.0</td>\n      <td>2303400556</td>\n      <td>47999</td>\n      <td>Other</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>11</td>\n    </tr>\n    <tr>\n      <th>16225</th>\n      <td>2061593</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>320962633</td>\n      <td>3</td>\n      <td>1450.0</td>\n      <td>2716610817</td>\n      <td>23828</td>\n      <td>Other</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>103823</th>\n      <td>2078097</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>2074135650</td>\n      <td>45</td>\n      <td>3342.0</td>\n      <td>4098758075</td>\n      <td>61174</td>\n      <td>Other</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>60929</th>\n      <td>2366870</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>1232582129</td>\n      <td>0</td>\n      <td>0.0</td>\n      <td>2855109799</td>\n      <td>23633</td>\n      <td>Other</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>2</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"%%time\n\nimport pathlib\n\nmax_samples = 17089 # number of unique eeg_ids\nsubsamples = train_df.iloc[0:max_samples]\n\nchunks = 8\n\neegs = {}\nspectrograms = {}\n\neegs_path = pathlib.Path(\"/kaggle/input/hms-harmful-brain-activity-classification/train_eegs\")\nspts_path = pathlib.Path(\"/kaggle/input/hms-harmful-brain-activity-classification/train_spectrograms\")\n\ncount = 0\nfor index, values in subsamples.iterrows():\n    eeg_path = eegs_path.joinpath(f\"{values['eeg_id']}.parquet\")\n    eeg_id = eeg_path.name.split(\".\")[0]\n    if eeg_id not in eegs and eeg_path.exists():\n        eeg_df = pd.read_parquet(eeg_path)\n        eegs[eeg_id] = eeg_df\n\n#     spt_path = spts_path.joinpath(f\"{values['spectrogram_id']}.parquet\")\n#     spt_id = spt_path.name.split(\".\")[0]\n#     if spt_id not in spectrograms and spt_path.exists():\n#         spt_df = pd.read_parquet(spt_path).describe()\n#         spectrograms[spt_id] = spt_df\n\nprint(f\"Number of EEGs: {len(eegs)}\")\nprint(f\"Number of spectrograms: {len(spectrograms)}\")\neegs[\"568657\"]","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:24:48.563053Z","iopub.execute_input":"2024-04-25T23:24:48.563456Z","iopub.status.idle":"2024-04-25T23:31:43.831495Z","shell.execute_reply.started":"2024-04-25T23:24:48.563428Z","shell.execute_reply":"2024-04-25T23:31:43.830292Z"},"trusted":true},"execution_count":15,"outputs":[{"name":"stdout","text":"Number of EEGs: 17089\nNumber of spectrograms: 0\nCPU times: user 2min 57s, sys: 53.7 s, total: 3min 50s\nWall time: 6min 55s\n","output_type":"stream"},{"execution_count":15,"output_type":"execute_result","data":{"text/plain":"              Fp1          F3          C3         P3          F7          T3  \\\n0      -75.360001   86.379997   65.470001  62.580002  170.350006   92.370003   \n1     -107.739998   53.139999   32.590000  21.950001  140.500000   59.070000   \n2     -103.050003   46.330002   10.750000   9.150000  137.820007   50.950001   \n3      -75.099998   77.870003   40.150002  31.790001  166.630005   76.769997   \n4      -97.919998   58.209999   27.330000   5.340000  144.080002   47.200001   \n...           ...         ...         ...        ...         ...         ...   \n13195 -160.800003 -114.349998 -129.779999 -59.860001 -166.770004  -55.310001   \n13196 -169.919998 -132.699997 -154.160004 -69.129997 -184.130005  -77.470001   \n13197 -141.600006  -99.709999 -120.599998 -28.770000 -154.869995  -47.549999   \n13198 -155.550003 -105.559998 -116.540001 -31.240000 -163.490005  -60.480000   \n13199 -184.429993 -145.580002 -161.080002 -66.150002 -202.330002 -107.309998   \n\n              T5         O1         Fz         Cz          Pz         Fp2  \\\n0      39.680000  89.870003  18.260000 -28.440001  -15.190000   16.930000   \n1       4.260000  53.310001 -18.490000 -63.270000  -52.110001  -13.230000   \n2      -3.500000  45.070000 -20.879999 -66.629997  -69.750000   -9.200000   \n3      17.990000  67.650002  11.140000 -32.950001  -38.509998   14.770000   \n4     -10.430000  40.250000 -12.350000 -52.500000  -54.919998  -10.070000   \n...          ...        ...        ...        ...         ...         ...   \n13195 -61.900002 -66.510002 -40.220001 -44.689999 -126.870003 -119.510002   \n13196 -75.959999 -75.910004 -54.389999 -57.410000 -140.020004 -127.639999   \n13197 -41.610001 -36.299999 -22.420000 -16.940001  -94.050003 -100.709999   \n13198 -51.320000 -43.490002 -34.860001 -22.889999  -84.669998 -116.760002   \n13199 -92.260002 -77.970001 -72.849998 -54.849998 -120.160004 -145.029999   \n\n               F4          C4         P4          F8          T4          T6  \\\n0       13.810000  -42.160000  78.099998 -143.649994  121.239998   -1.470000   \n1      -16.420000  -80.430000  64.449997 -168.500000   88.400002  -28.520000   \n2      -21.400000  -93.089996   5.120000 -176.089996   51.689999  -38.639999   \n3        9.790000  -66.480003  48.220001 -147.990005   86.629997  -18.639999   \n4       -8.040000  -90.820000  67.269997 -164.710007   80.680000  -36.520000   \n...           ...         ...        ...         ...         ...         ...   \n13195  -89.480003 -176.240005   1.300000 -161.649994   -6.820000  102.620003   \n13196 -107.169998 -191.160004 -60.020000 -181.389999  -40.779999   92.239998   \n13197  -75.910004 -145.940002 -26.469999 -152.240005    2.190000  120.709999   \n13198  -77.989998 -138.279999  23.129999 -149.500000   28.150000  118.300003   \n13199 -108.199997 -169.899994 -35.790001 -181.940002  -15.490000   90.540001   \n\n              O2           EKG  \n0      72.550003  -3090.090088  \n1      40.250000   5560.439941  \n2      31.820000  -4161.450195  \n3      62.509998  31769.970703  \n4      41.830002   6879.720215  \n...          ...           ...  \n13195 -46.330002   2097.229980  \n13196 -59.740002   1954.630005  \n13197 -19.320000  -3010.149902  \n13198 -21.100000    280.119995  \n13199 -55.959999   3064.830078  \n\n[13200 rows x 20 columns]","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Fp1</th>\n      <th>F3</th>\n      <th>C3</th>\n      <th>P3</th>\n      <th>F7</th>\n      <th>T3</th>\n      <th>T5</th>\n      <th>O1</th>\n      <th>Fz</th>\n      <th>Cz</th>\n      <th>Pz</th>\n      <th>Fp2</th>\n      <th>F4</th>\n      <th>C4</th>\n      <th>P4</th>\n      <th>F8</th>\n      <th>T4</th>\n      <th>T6</th>\n      <th>O2</th>\n      <th>EKG</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>-75.360001</td>\n      <td>86.379997</td>\n      <td>65.470001</td>\n      <td>62.580002</td>\n      <td>170.350006</td>\n      <td>92.370003</td>\n      <td>39.680000</td>\n      <td>89.870003</td>\n      <td>18.260000</td>\n      <td>-28.440001</td>\n      <td>-15.190000</td>\n      <td>16.930000</td>\n      <td>13.810000</td>\n      <td>-42.160000</td>\n      <td>78.099998</td>\n      <td>-143.649994</td>\n      <td>121.239998</td>\n      <td>-1.470000</td>\n      <td>72.550003</td>\n      <td>-3090.090088</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>-107.739998</td>\n      <td>53.139999</td>\n      <td>32.590000</td>\n      <td>21.950001</td>\n      <td>140.500000</td>\n      <td>59.070000</td>\n      <td>4.260000</td>\n      <td>53.310001</td>\n      <td>-18.490000</td>\n      <td>-63.270000</td>\n      <td>-52.110001</td>\n      <td>-13.230000</td>\n      <td>-16.420000</td>\n      <td>-80.430000</td>\n      <td>64.449997</td>\n      <td>-168.500000</td>\n      <td>88.400002</td>\n      <td>-28.520000</td>\n      <td>40.250000</td>\n      <td>5560.439941</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>-103.050003</td>\n      <td>46.330002</td>\n      <td>10.750000</td>\n      <td>9.150000</td>\n      <td>137.820007</td>\n      <td>50.950001</td>\n      <td>-3.500000</td>\n      <td>45.070000</td>\n      <td>-20.879999</td>\n      <td>-66.629997</td>\n      <td>-69.750000</td>\n      <td>-9.200000</td>\n      <td>-21.400000</td>\n      <td>-93.089996</td>\n      <td>5.120000</td>\n      <td>-176.089996</td>\n      <td>51.689999</td>\n      <td>-38.639999</td>\n      <td>31.820000</td>\n      <td>-4161.450195</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>-75.099998</td>\n      <td>77.870003</td>\n      <td>40.150002</td>\n      <td>31.790001</td>\n      <td>166.630005</td>\n      <td>76.769997</td>\n      <td>17.990000</td>\n      <td>67.650002</td>\n      <td>11.140000</td>\n      <td>-32.950001</td>\n      <td>-38.509998</td>\n      <td>14.770000</td>\n      <td>9.790000</td>\n      <td>-66.480003</td>\n      <td>48.220001</td>\n      <td>-147.990005</td>\n      <td>86.629997</td>\n      <td>-18.639999</td>\n      <td>62.509998</td>\n      <td>31769.970703</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>-97.919998</td>\n      <td>58.209999</td>\n      <td>27.330000</td>\n      <td>5.340000</td>\n      <td>144.080002</td>\n      <td>47.200001</td>\n      <td>-10.430000</td>\n      <td>40.250000</td>\n      <td>-12.350000</td>\n      <td>-52.500000</td>\n      <td>-54.919998</td>\n      <td>-10.070000</td>\n      <td>-8.040000</td>\n      <td>-90.820000</td>\n      <td>67.269997</td>\n      <td>-164.710007</td>\n      <td>80.680000</td>\n      <td>-36.520000</td>\n      <td>41.830002</td>\n      <td>6879.720215</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>13195</th>\n      <td>-160.800003</td>\n      <td>-114.349998</td>\n      <td>-129.779999</td>\n      <td>-59.860001</td>\n      <td>-166.770004</td>\n      <td>-55.310001</td>\n      <td>-61.900002</td>\n      <td>-66.510002</td>\n      <td>-40.220001</td>\n      <td>-44.689999</td>\n      <td>-126.870003</td>\n      <td>-119.510002</td>\n      <td>-89.480003</td>\n      <td>-176.240005</td>\n      <td>1.300000</td>\n      <td>-161.649994</td>\n      <td>-6.820000</td>\n      <td>102.620003</td>\n      <td>-46.330002</td>\n      <td>2097.229980</td>\n    </tr>\n    <tr>\n      <th>13196</th>\n      <td>-169.919998</td>\n      <td>-132.699997</td>\n      <td>-154.160004</td>\n      <td>-69.129997</td>\n      <td>-184.130005</td>\n      <td>-77.470001</td>\n      <td>-75.959999</td>\n      <td>-75.910004</td>\n      <td>-54.389999</td>\n      <td>-57.410000</td>\n      <td>-140.020004</td>\n      <td>-127.639999</td>\n      <td>-107.169998</td>\n      <td>-191.160004</td>\n      <td>-60.020000</td>\n      <td>-181.389999</td>\n      <td>-40.779999</td>\n      <td>92.239998</td>\n      <td>-59.740002</td>\n      <td>1954.630005</td>\n    </tr>\n    <tr>\n      <th>13197</th>\n      <td>-141.600006</td>\n      <td>-99.709999</td>\n      <td>-120.599998</td>\n      <td>-28.770000</td>\n      <td>-154.869995</td>\n      <td>-47.549999</td>\n      <td>-41.610001</td>\n      <td>-36.299999</td>\n      <td>-22.420000</td>\n      <td>-16.940001</td>\n      <td>-94.050003</td>\n      <td>-100.709999</td>\n      <td>-75.910004</td>\n      <td>-145.940002</td>\n      <td>-26.469999</td>\n      <td>-152.240005</td>\n      <td>2.190000</td>\n      <td>120.709999</td>\n      <td>-19.320000</td>\n      <td>-3010.149902</td>\n    </tr>\n    <tr>\n      <th>13198</th>\n      <td>-155.550003</td>\n      <td>-105.559998</td>\n      <td>-116.540001</td>\n      <td>-31.240000</td>\n      <td>-163.490005</td>\n      <td>-60.480000</td>\n      <td>-51.320000</td>\n      <td>-43.490002</td>\n      <td>-34.860001</td>\n      <td>-22.889999</td>\n      <td>-84.669998</td>\n      <td>-116.760002</td>\n      <td>-77.989998</td>\n      <td>-138.279999</td>\n      <td>23.129999</td>\n      <td>-149.500000</td>\n      <td>28.150000</td>\n      <td>118.300003</td>\n      <td>-21.100000</td>\n      <td>280.119995</td>\n    </tr>\n    <tr>\n      <th>13199</th>\n      <td>-184.429993</td>\n      <td>-145.580002</td>\n      <td>-161.080002</td>\n      <td>-66.150002</td>\n      <td>-202.330002</td>\n      <td>-107.309998</td>\n      <td>-92.260002</td>\n      <td>-77.970001</td>\n      <td>-72.849998</td>\n      <td>-54.849998</td>\n      <td>-120.160004</td>\n      <td>-145.029999</td>\n      <td>-108.199997</td>\n      <td>-169.899994</td>\n      <td>-35.790001</td>\n      <td>-181.940002</td>\n      <td>-15.490000</td>\n      <td>90.540001</td>\n      <td>-55.959999</td>\n      <td>3064.830078</td>\n    </tr>\n  </tbody>\n</table>\n<p>13200 rows × 20 columns</p>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"%%time\n\n# for each feature column in an EEG, \"describe\" the data\n# by computing the mean, std, min, 25%, 50%, 75%, max\n\neeg_stats = {}\nfor key, eeg in eegs.items():\n    eeg_stat = eeg.describe().to_numpy().flatten()\n    eeg_stat_len = eeg_stat.shape\n    eeg_stats[key] = eeg_stat\n    \nprint(\"Shape:\", eeg_stat_len)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:34:05.649135Z","iopub.execute_input":"2024-04-25T23:34:05.649599Z","iopub.status.idle":"2024-04-25T23:47:12.43575Z","shell.execute_reply.started":"2024-04-25T23:34:05.649568Z","shell.execute_reply":"2024-04-25T23:47:12.434208Z"},"trusted":true},"execution_count":16,"outputs":[{"name":"stdout","text":"Shape: (160,)\nCPU times: user 13min 4s, sys: 1.42 ms, total: 13min 4s\nWall time: 13min 6s\n","output_type":"stream"}]},{"cell_type":"code","source":"import pickle\n\nwith open('/kaggle/working/eeg_stats.pickle', 'wb') as file:\n    pickle.dump(eeg_stats, file, pickle.HIGHEST_PROTOCOL)\n    \nLOAD_PICKLE = False\nif LOAD_PICKLE:\n    with open('/kaggle/working/eeg_stats.pickle', 'rb') as file:\n        eeg_stats = pickle.load(file)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:48:34.921798Z","iopub.execute_input":"2024-04-25T23:48:34.922484Z","iopub.status.idle":"2024-04-25T23:48:35.036446Z","shell.execute_reply.started":"2024-04-25T23:48:34.922451Z","shell.execute_reply":"2024-04-25T23:48:35.035346Z"},"trusted":true},"execution_count":17,"outputs":[]},{"cell_type":"code","source":"Y_train = (train_df.iloc[0:max_samples])[[\"eeg_id\", \"expert_consensus\"]].set_index(\"eeg_id\")\n\n# convert expert_consensus to integer categories\nexpert_consensus_factors = Y_train[\"expert_consensus\"].factorize()\nY_train[\"expert_consensus\"] = expert_consensus_factors[0]\n\n# convert votes to probabilities that sum to 1\ntrain_df_vote_probs = (train_df.iloc[0:max_samples])[[\"eeg_id\", \"seizure_vote\", \"lpd_vote\", \"gpd_vote\", \"lrda_vote\", \"grda_vote\", \"other_vote\"]].set_index(\"eeg_id\")\ntrain_df_vote_probs = train_df_vote_probs.div(train_df_vote_probs.sum(axis=1), axis=0)\n\n# join the two dataframes together by eeg_id\nY_train = Y_train.join(train_df_vote_probs)\n\nY_train.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:49:48.808136Z","iopub.execute_input":"2024-04-25T23:49:48.808867Z","iopub.status.idle":"2024-04-25T23:49:48.861274Z","shell.execute_reply.started":"2024-04-25T23:49:48.808815Z","shell.execute_reply":"2024-04-25T23:49:48.859445Z"},"trusted":true},"execution_count":19,"outputs":[{"execution_count":19,"output_type":"execute_result","data":{"text/plain":"        expert_consensus  seizure_vote  lpd_vote  gpd_vote  lrda_vote  \\\neeg_id                                                                  \n568657                 0           0.0  0.000000      0.25   0.000000   \n582999                 1           0.0  0.857143      0.00   0.071429   \n642382                 0           0.0  0.000000      0.00   0.000000   \n751790                 2           0.0  0.000000      1.00   0.000000   \n778705                 0           0.0  0.000000      0.00   0.000000   \n\n        grda_vote  other_vote  \neeg_id                         \n568657   0.166667    0.583333  \n582999   0.000000    0.071429  \n642382   0.000000    1.000000  \n751790   0.000000    0.000000  \n778705   0.000000    1.000000  ","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>expert_consensus</th>\n      <th>seizure_vote</th>\n      <th>lpd_vote</th>\n      <th>gpd_vote</th>\n      <th>lrda_vote</th>\n      <th>grda_vote</th>\n      <th>other_vote</th>\n    </tr>\n    <tr>\n      <th>eeg_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>568657</th>\n      <td>0</td>\n      <td>0.0</td>\n      <td>0.000000</td>\n      <td>0.25</td>\n      <td>0.000000</td>\n      <td>0.166667</td>\n      <td>0.583333</td>\n    </tr>\n    <tr>\n      <th>582999</th>\n      <td>1</td>\n      <td>0.0</td>\n      <td>0.857143</td>\n      <td>0.00</td>\n      <td>0.071429</td>\n      <td>0.000000</td>\n      <td>0.071429</td>\n    </tr>\n    <tr>\n      <th>642382</th>\n      <td>0</td>\n      <td>0.0</td>\n      <td>0.000000</td>\n      <td>0.00</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n      <td>1.000000</td>\n    </tr>\n    <tr>\n      <th>751790</th>\n      <td>2</td>\n      <td>0.0</td>\n      <td>0.000000</td>\n      <td>1.00</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n    </tr>\n    <tr>\n      <th>778705</th>\n      <td>0</td>\n      <td>0.0</td>\n      <td>0.000000</td>\n      <td>0.00</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n      <td>1.000000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"%%time\n\n# create matrix that will contain the data\nnum_cols = eeg_stat_len[0]\nnum_rows = len(eeg_stats)\ndata = np.ndarray((num_rows, num_cols), dtype=np.float32)\n# targets = Y_train.to_numpy().reshape((num_rows,))\n\nrow_index = 0\nfor key, eeg in eeg_stats.items():\n    data[row_index, :] = eeg\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler\nX_train, X_test, y_train, y_test = train_test_split(\n    data, Y_train, test_size=0.3, random_state=0\n)\n\ny_train_np = y_train[[\"expert_consensus\"]].to_numpy().reshape((len(y_train, )))\ny_test_np = y_test[[\"expert_consensus\"]].to_numpy().reshape((len(y_test, )))\n\n# scaler = StandardScaler()\n# X_train = scaler.fit_transform(np.nan_to_num(X_train))\n# X_test = scaler.transform(np.nan_to_num(X_test))","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:50:45.155016Z","iopub.execute_input":"2024-04-25T23:50:45.155747Z","iopub.status.idle":"2024-04-25T23:50:45.198586Z","shell.execute_reply.started":"2024-04-25T23:50:45.155711Z","shell.execute_reply":"2024-04-25T23:50:45.197661Z"},"trusted":true},"execution_count":20,"outputs":[{"name":"stdout","text":"CPU times: user 32.2 ms, sys: 0 ns, total: 32.2 ms\nWall time: 34.3 ms\n","output_type":"stream"}]},{"cell_type":"code","source":"%%time\n\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.ensemble import HistGradientBoostingClassifier\nfrom scipy.stats import uniform\n\nparameters = {\n    'learning_rate': [0.5, 1.0, 1.5],\n    'max_depth': [1, 2, 3],\n    'l2_regularization': [0, 0.5, 1.0]\n}\n\ngbm = GridSearchCV(HistGradientBoostingClassifier(), parameters, n_jobs=2)\ngbm.fit(np.nan_to_num(X_train), y_train_np)\n\ngbm.best_params_\n\n# gbm = HistGradientBoostingClassifier(\n#     learning_rate=1.0,\n#     max_depth=2,\n#     random_state=0\n# ).fit(np.nan_to_num(X_train), y_train_np)\n# predicts class probabilities\n# GradientBoostingClassifier().predict_proba()","metadata":{"execution":{"iopub.status.busy":"2024-04-26T00:51:38.240161Z","iopub.execute_input":"2024-04-26T00:51:38.240571Z","iopub.status.idle":"2024-04-26T00:55:30.580983Z","shell.execute_reply.started":"2024-04-26T00:51:38.240543Z","shell.execute_reply":"2024-04-26T00:55:30.579493Z"},"trusted":true},"execution_count":47,"outputs":[{"name":"stdout","text":"CPU times: user 2.77 s, sys: 942 ms, total: 3.71 s\nWall time: 3min 52s\n","output_type":"stream"},{"execution_count":47,"output_type":"execute_result","data":{"text/plain":"{'l2_regularization': 0, 'learning_rate': 0.5, 'max_depth': 1}"},"metadata":{}}]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, classification_report \n\ny_pred = gbm.predict(np.nan_to_num(X_train))\nprint(f\"Train Accuracy: {accuracy_score(y_train_np, y_pred):.3f}\\n\")\nprint(classification_report(y_train_np, y_pred, target_names=expert_consensus_factors[1]))","metadata":{"execution":{"iopub.status.busy":"2024-04-26T00:05:58.37967Z","iopub.execute_input":"2024-04-26T00:05:58.380474Z","iopub.status.idle":"2024-04-26T00:05:58.464459Z","shell.execute_reply.started":"2024-04-26T00:05:58.38043Z","shell.execute_reply":"2024-04-26T00:05:58.463344Z"},"trusted":true},"execution_count":39,"outputs":[{"name":"stdout","text":"Train Accuracy: 0.420\n\n              precision    recall  f1-score   support\n\n       Other       0.42      1.00      0.59      5030\n         LPD       0.00      0.00      0.00      1815\n         GPD       0.00      0.00      0.00      1262\n     Seizure       0.00      0.00      0.00      1957\n        GRDA       0.00      0.00      0.00      1262\n        LRDA       0.00      0.00      0.00       636\n\n    accuracy                           0.42     11962\n   macro avg       0.07      0.17      0.10     11962\nweighted avg       0.18      0.42      0.25     11962\n\n","output_type":"stream"},{"name":"stderr","text":"/opt/conda/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n  _warn_prf(average, modifier, msg_start, len(result))\n/opt/conda/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n  _warn_prf(average, modifier, msg_start, len(result))\n/opt/conda/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n  _warn_prf(average, modifier, msg_start, len(result))\n","output_type":"stream"}]},{"cell_type":"code","source":"y_pred = gbm.predict(np.nan_to_num(X_test))\nprint(f\"Test Accuracy: {accuracy_score(y_test_np, y_pred):.3f}\\n\")\nprint(classification_report(y_test_np, y_pred, target_names=expert_consensus_factors[1]))","metadata":{"execution":{"iopub.status.busy":"2024-04-26T00:06:06.92747Z","iopub.execute_input":"2024-04-26T00:06:06.92786Z","iopub.status.idle":"2024-04-26T00:06:06.971848Z","shell.execute_reply.started":"2024-04-26T00:06:06.927833Z","shell.execute_reply":"2024-04-26T00:06:06.970969Z"},"trusted":true},"execution_count":40,"outputs":[{"name":"stdout","text":"Test Accuracy: 0.422\n\n              precision    recall  f1-score   support\n\n       Other       0.42      1.00      0.59      2166\n         LPD       0.00      0.00      0.00       762\n         GPD       0.00      0.00      0.00       525\n     Seizure       0.00      0.00      0.00       828\n        GRDA       0.00      0.00      0.00       566\n        LRDA       0.00      0.00      0.00       280\n\n    accuracy                           0.42      5127\n   macro avg       0.07      0.17      0.10      5127\nweighted avg       0.18      0.42      0.25      5127\n\n","output_type":"stream"},{"name":"stderr","text":"/opt/conda/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n  _warn_prf(average, modifier, msg_start, len(result))\n/opt/conda/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n  _warn_prf(average, modifier, msg_start, len(result))\n/opt/conda/lib/python3.10/site-packages/sklearn/metrics/_classification.py:1344: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n  _warn_prf(average, modifier, msg_start, len(result))\n","output_type":"stream"}]},{"cell_type":"markdown","source":"## Logistic Regression","metadata":{}},{"cell_type":"code","source":"from sklearn.linear_model import Perceptron\nperceptron = Perceptron(\n    tol=1e-3,\n    random_state=0\n).fit(np.nan_to_num(X_train), y_train_np)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:51:06.816094Z","iopub.execute_input":"2024-04-25T23:51:06.81673Z","iopub.status.idle":"2024-04-25T23:51:07.398296Z","shell.execute_reply.started":"2024-04-25T23:51:06.816696Z","shell.execute_reply":"2024-04-25T23:51:07.396487Z"},"trusted":true},"execution_count":24,"outputs":[]},{"cell_type":"code","source":"y_pred = perceptron.predict(np.nan_to_num(X_train))\naccuracy_score(y_train_np, y_pred)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:51:09.438354Z","iopub.execute_input":"2024-04-25T23:51:09.438778Z","iopub.status.idle":"2024-04-25T23:51:09.474869Z","shell.execute_reply.started":"2024-04-25T23:51:09.438735Z","shell.execute_reply":"2024-04-25T23:51:09.473585Z"},"trusted":true},"execution_count":25,"outputs":[{"execution_count":25,"output_type":"execute_result","data":{"text/plain":"0.1860056846681157"},"metadata":{}}]},{"cell_type":"code","source":"y_pred = perceptron.predict(np.nan_to_num(X_test))\naccuracy_score(y_test_np, y_pred)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:51:12.017487Z","iopub.execute_input":"2024-04-25T23:51:12.018051Z","iopub.status.idle":"2024-04-25T23:51:12.036211Z","shell.execute_reply.started":"2024-04-25T23:51:12.017987Z","shell.execute_reply":"2024-04-25T23:51:12.034875Z"},"trusted":true},"execution_count":26,"outputs":[{"execution_count":26,"output_type":"execute_result","data":{"text/plain":"0.18509849814706456"},"metadata":{}}]},{"cell_type":"markdown","source":"## Save Results","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport pandas.api.types\n\ndef kl_divergence(solution: pd.DataFrame, submission: pd.DataFrame, epsilon: float):\n    # Overwrite solution for convenience\n    for col in solution.columns:\n        # Prevent issue with populating int columns with floats\n        if not pandas.api.types.is_float_dtype(solution[col]):\n            solution[col] = solution[col].astype(float)\n\n        # Clip both the min and max following Kaggle conventions for related metrics like log loss\n        # Clipping the max avoids cases where the loss would be infinite or undefined, clipping the min\n        # prevents users from playing games with the 20th decimal place of predictions.\n        submission[col] = np.clip(submission[col], epsilon, 1 - epsilon)\n\n        y_nonzero_indices = solution[col] != 0\n        solution[col] = solution[col].astype(float)\n        solution.loc[y_nonzero_indices, col] = solution.loc[y_nonzero_indices, col] * np.log(solution.loc[y_nonzero_indices, col] / submission.loc[y_nonzero_indices, col])\n        # Set the loss equal to zero where y_true equals zero following the scipy convention:\n        # https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.rel_entr.html#scipy.special.rel_entr\n        solution.loc[~y_nonzero_indices, col] = 0\n\n    return np.average(solution.sum(axis=1))\n\ny_pred = gbm.predict_proba(np.nan_to_num(X_test))\nsubmission = pd.DataFrame({'eeg_id': y_test.reset_index()[\"eeg_id\"].values})\nsubmission[expert_consensus_factors[1]] = y_pred\nsubmission = submission.rename(columns={s: f\"{s.lower()}_vote\" for s in expert_consensus_factors[1]})\nsubmission = submission.set_index(\"eeg_id\")\nsubmission = submission.loc[:,[\"seizure_vote\", \"lpd_vote\", \"gpd_vote\", \"lrda_vote\", \"grda_vote\", \"other_vote\"]]\nprint(\"First Five of Submission:\")\nprint(submission.head())\n\nsolution = y_test.drop(labels=[\"expert_consensus\"], axis=\"columns\")\nprint(\"\\nFirst Five of Solution:\")\nprint(solution.head())\n\nprint(f\"\\nKL Divergence: {kl_divergence(solution, submission, 1e-15):.3f}\")","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:52:11.415918Z","iopub.execute_input":"2024-04-25T23:52:11.416306Z","iopub.status.idle":"2024-04-25T23:52:11.491014Z","shell.execute_reply.started":"2024-04-25T23:52:11.416279Z","shell.execute_reply":"2024-04-25T23:52:11.48985Z"},"trusted":true},"execution_count":29,"outputs":[{"name":"stdout","text":"First Five of Submission:\n            seizure_vote  lpd_vote  gpd_vote  lrda_vote  grda_vote  other_vote\neeg_id                                                                        \n278696480       0.100655  0.167821  0.070623   0.071816   0.094099    0.494987\n1559899685      0.156126  0.176294  0.089216   0.078955   0.090986    0.408422\n2180916939      0.149985  0.124122  0.091781   0.045657   0.093601    0.494854\n647433622       0.101066  0.101386  0.076901   0.068844   0.071281    0.580522\n2810902836      0.148916  0.123238  0.088157   0.035735   0.112627    0.491327\n\nFirst Five of Solution:\n            seizure_vote  lpd_vote  gpd_vote  lrda_vote  grda_vote  other_vote\neeg_id                                                                        \n278696480           1.00       0.0      0.00        0.0        0.0         0.0\n1559899685          0.25       0.0      0.75        0.0        0.0         0.0\n2180916939          0.00       0.0      0.00        0.0        1.0         0.0\n647433622           0.00       0.0      0.00        0.0        1.0         0.0\n2810902836          1.00       0.0      0.00        0.0        0.0         0.0\n\nKL Divergence: 1.312\n","output_type":"stream"}]},{"cell_type":"markdown","source":"## Hyperparameter Search","metadata":{}},{"cell_type":"code","source":"%%time\n\nfrom sklearn.model_selection import GridSearchCV\n\nhyperparam_search = False\n\nif hyperparam_search:\n    X_train, X_test, y_train, y_test = train_test_split(\n        data, Y_train, train_size=0.1, test_size=0.03, random_state=0\n    )\n\n    y_train_np = y_train[[\"expert_consensus\"]].to_numpy().reshape((len(y_train, )))\n    y_test_np = y_test[[\"expert_consensus\"]].to_numpy().reshape((len(y_test, )))\n    \n    hyperparams = {\n        \"learning_rate\": [1.0, 3.0, 5.0],\n        \"max_depth\": [1, 5, 9],\n        \"min_samples_split\": [2, 5],\n        \"min_samples_leaf\": [1, 3]\n    }\n    \n    clf = GridSearchCV(\n        estimator=HistGradientBoostingClassifier(),\n        param_grid=hyperparams\n    )\n    \n    clf.fit(np.nan_to_num(X_train), y_train_np)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:22:15.147734Z","iopub.status.idle":"2024-04-25T23:22:15.148644Z","shell.execute_reply.started":"2024-04-25T23:22:15.148346Z","shell.execute_reply":"2024-04-25T23:22:15.148383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Distribution of Data","metadata":{}},{"cell_type":"code","source":"import plotly.express as px\n\nfig = px.pie(\n    train_df,\n    values=train_df[\"expert_consensus\"].value_counts().values,\n    names=train_df[\"expert_consensus\"].value_counts().index,\n    title='Count of Harmful Brain Activity Classifications by Type',\n    width=600, height=600\n)\nfig.update_traces(hoverinfo='label+percent', textinfo='label+value+percent')\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-26T01:20:10.176344Z","iopub.execute_input":"2024-04-26T01:20:10.176855Z","iopub.status.idle":"2024-04-26T01:20:13.609069Z","shell.execute_reply.started":"2024-04-26T01:20:10.17682Z","shell.execute_reply":"2024-04-26T01:20:13.605738Z"},"trusted":true},"execution_count":48,"outputs":[{"output_type":"display_data","data":{"text/html":"        <script type=\"text/javascript\">\n        window.PlotlyConfig = {MathJaxConfig: 'local'};\n        if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}\n        if (typeof require !== 'undefined') {\n        require.undef(\"plotly\");\n        requirejs.config({\n            paths: {\n                'plotly': ['https://cdn.plot.ly/plotly-2.27.0.min']\n            }\n        });\n        require(['plotly'], function(Plotly) {\n            window._Plotly = Plotly;\n        });\n        }\n        </script>\n        "},"metadata":{}},{"output_type":"display_data","data":{"text/html":"<div>                            <div id=\"896d48a7-a730-4729-843d-b6411328a63d\" class=\"plotly-graph-div\" style=\"height:600px; width:600px;\"></div>            <script type=\"text/javascript\">                require([\"plotly\"], function(Plotly) {                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById(\"896d48a7-a730-4729-843d-b6411328a63d\")) {                    Plotly.newPlot(                        \"896d48a7-a730-4729-843d-b6411328a63d\",                        [{\"domain\":{\"x\":[0.0,1.0],\"y\":[0.0,1.0]},\"hovertemplate\":\"label=%{label}\\u003cbr\\u003evalue=%{value}\\u003cextra\\u003e\\u003c\\u002fextra\\u003e\",\"labels\":[\"Other\",\"Seizure\",\"LPD\",\"GRDA\",\"GPD\",\"LRDA\"],\"legendgroup\":\"\",\"name\":\"\",\"showlegend\":true,\"values\":[7196,2785,2577,1828,1787,916],\"type\":\"pie\",\"hoverinfo\":\"label+percent\",\"textinfo\":\"label+value+percent\"}],                        {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"type\":\"heatmapgl\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"type\":\"mesh3d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"parcoords\":[{\"type\":\"parcoords\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"type\":\"scatterpolargl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"scattergeo\":[{\"type\":\"scattergeo\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"type\":\"scatterpolar\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"scattergl\":[{\"type\":\"scattergl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"type\":\"scatter3d\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"type\":\"scattermapbox\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"type\":\"scatterternary\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"type\":\"scattercarpet\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}]},\"layout\":{\"autotypenumbers\":\"strict\",\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"bgcolor\":\"#E5ECF6\",\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"ternary\":{\"bgcolor\":\"#E5ECF6\",\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]]},\"xaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"yaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"geo\":{\"bgcolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"subunitcolor\":\"white\",\"showland\":true,\"showlakes\":true,\"lakecolor\":\"white\"},\"title\":{\"x\":0.05},\"mapbox\":{\"style\":\"light\"}}},\"legend\":{\"tracegroupgap\":0},\"title\":{\"text\":\"Count of Harmful Brain Activity Classifications by Type\"},\"height\":600,\"width\":600},                        {\"responsive\": true}                    ).then(function(){\n                            \nvar gd = document.getElementById('896d48a7-a730-4729-843d-b6411328a63d');\nvar x = new MutationObserver(function (mutations, observer) {{\n        var display = window.getComputedStyle(gd).display;\n        if (!display || display === 'none') {{\n            console.log([gd, 'removed!']);\n            Plotly.purge(gd);\n            observer.disconnect();\n        }}\n}});\n\n// Listen for the removal of the full notebook cells\nvar notebookContainer = gd.closest('#notebook-container');\nif (notebookContainer) {{\n    x.observe(notebookContainer, {childList: true});\n}}\n\n// Listen for the clearing of the current output cell\nvar outputEl = gd.closest('.output');\nif (outputEl) {{\n    x.observe(outputEl, {childList: true});\n}}\n\n                        })                };                });            </script>        </div>"},"metadata":{}}]}]}