# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# + [markdown] colab_type="text" id="view-in-github"
# <a href="https://colab.research.google.com/github/i1idan/schizophrenia-diagnosis-eeg-signals/blob/main/train.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + colab={"base_uri": "https://localhost:8080/"} id="B7YlhS4gYc8s" outputId="7ed228ec-718f-43ae-bf46-9511ead2581e"
from google.colab import drive
drive.mount('/content/drive')

# + [markdown] id="FB7LuLHBlpvM"
# # Clone the Repository

# + colab={"base_uri": "https://localhost:8080/"} id="0d35c532" outputId="cb3b1d58-fdfb-48f5-9fa6-dadc8a12fc24"
# !git clone https://github.com/i1idan/schizophrenia-diagnosis-eeg-signals.git

# + colab={"base_uri": "https://localhost:8080/"} id="6X3Blwu5ZKWq" outputId="77e2207f-1941-4df9-d692-dd19d7811671"
import os
os.chdir('/content/schizophrenia-diagnosis-eeg-signals')
# !git pull origin main

# + [markdown] id="pfZzZofyZVB_"
# # Install Requirements

# + colab={"base_uri": "https://localhost:8080/"} id="f3uUKOYfZUiA" outputId="1e927faf-42ef-421a-f8e8-7d640bfb6b07"
# !pip install -r requirements.txt

# + [markdown] id="lCirzbPuZyuQ"
# # Get Data

# + colab={"base_uri": "https://localhost:8080/"} id="tsJQv-K5Z0k-" outputId="87b9103c-18b2-4af4-ab91-2797b4e663e3"
# !gdown --id 1jnWHWrArzJQIvny0cQkfPP42hEJAp_56
# !mv DATA.mat /content/schizophrenia-diagnosis-eeg-signals/data/DATA.mat

# + [markdown] id="4130c324"
# # Training Models

# + id="98c9e21c"
# Number of training in a sequence
multi_train = 10
epochs = 200
model_name = "WaveletCustom"
data_path = "./data/DATA.mat"
# checkpoints = "/content/drive/MyDrive/schizophrenia/checkpoints"
checkpoints = "./checkpoints"
batch_size = 4
early_stopping = 100
reduce_lr = 50
seed = 1234

# + colab={"base_uri": "https://localhost:8080/"} id="4bf6ef6b" outputId="87919b59-9c9b-4601-d6a1-c93a5e63b286"
csv_files = []
for n in range(multi_train):
    dir_name = f"{n}"
    new_seed = seed + n
    # preserve reproducibility
    # !PYTHONHASHSEED=0
    # !TF_DETERMINISTIC_OPS=0
    # !TF_CUDNN_DETERMINISTIC=0
    # !python train.py --model-name $model_name --epochs $epochs --seed $new_seed --dir-name $dir_name --checkpoints $checkpoints --batch-size $batch_size
    print(f"-----------------------------train {n} is done! ----------------------------------")

# + [markdown] id="0977a1b7"
# # Get Metrics

# + id="34cf3098" outputId="d581a2c5-f802-4e46-ebdb-8f9220da1b11"
from utils.group_metrics import get_mean_std
import os

csv_files = [os.path.join(checkpoints, model_name ,f"{n}", "log.csv") for n in range(multi_train)]
metrics = get_mean_std(csv_files, 
                       arguments=("accuracy", "loss", "val_accuracy", "val_loss"),
                       operators=(max, min, max, min)
                      )
print(metrics)

# + [markdown] id="be7e53a2"
# # Get Sensitivity & Specificity

# +
from utils.group_metrics import get_conf_mean_std
import os

conf_matrixes = [os.path.join(checkpoints, model_name ,f"{n}", "conf_matrix.csv") for n in range(multi_train)]

metrics = get_conf_mean_std(conf_matrixes)
metrics
# -

# _:)_

StarcoderdataJupyterScriptsDedupFiltered