Set path programmatically.
parent
38a405d378
commit
cad28c3fe8
|
@ -14,12 +14,13 @@
|
||||||
# ---
|
# ---
|
||||||
|
|
||||||
# %% jupyter={"outputs_hidden": false, "source_hidden": false}
|
# %% jupyter={"outputs_hidden": false, "source_hidden": false}
|
||||||
# %matplotlib inline
|
# from IPython.core.interactiveshell import InteractiveShell
|
||||||
import os
|
from pathlib import Path
|
||||||
import sys
|
|
||||||
|
|
||||||
|
# matplotlib inline
|
||||||
|
# import os
|
||||||
|
# import sys
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from IPython.core.interactiveshell import InteractiveShell
|
|
||||||
|
|
||||||
from machine_learning.helper import (
|
from machine_learning.helper import (
|
||||||
impute_encode_categorical_features,
|
impute_encode_categorical_features,
|
||||||
|
@ -28,30 +29,44 @@ from machine_learning.helper import (
|
||||||
run_all_classification_models,
|
run_all_classification_models,
|
||||||
)
|
)
|
||||||
|
|
||||||
InteractiveShell.ast_node_interactivity = "all"
|
# InteractiveShell.ast_node_interactivity = "all"
|
||||||
|
#
|
||||||
nb_dir = os.path.split(os.getcwd())[0]
|
# nb_dir = os.path.split(os.getcwd())[0]
|
||||||
if nb_dir not in sys.path:
|
# if nb_dir not in sys.path:
|
||||||
sys.path.append(nb_dir)
|
# sys.path.append(nb_dir)
|
||||||
|
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
CV_METHOD = "logo" # logo, half_logo, 5kfold
|
CV_METHOD = "logo" # logo, half_logo, 5kfold
|
||||||
# Cross-validation method (could be regarded as a hyperparameter)
|
# Cross-validation method (could be regarded as a hyperparameter)
|
||||||
|
print("CV_METHOD: " + CV_METHOD)
|
||||||
N_SL = 3 # Number of largest/smallest accuracies (of particular CV) outputs
|
N_SL = 3 # Number of largest/smallest accuracies (of particular CV) outputs
|
||||||
UNDERSAMPLING = False
|
UNDERSAMPLING = False
|
||||||
# (bool) If True this will train and test data on balanced dataset
|
# (bool) If True this will train and test data on balanced dataset
|
||||||
# (using undersampling method)
|
# (using undersampling method)
|
||||||
|
|
||||||
# %% jupyter={"outputs_hidden": false, "source_hidden": false}
|
# %% jupyter={"outputs_hidden": false, "source_hidden": false}
|
||||||
model_input = pd.read_csv(
|
PATH_BASE = Path("E:/STRAWresults/20230415")
|
||||||
"E:/STRAWresults/20230415/stress_event/input_appraisal_stressfulness_event_mean.csv"
|
|
||||||
|
SEGMENT_TYPE = "period"
|
||||||
|
print("SEGMENT_TYPE: " + SEGMENT_TYPE)
|
||||||
|
SEGMENT_LENGTH = "30_minutes_before"
|
||||||
|
print("SEGMENT_LENGTH: " + SEGMENT_LENGTH)
|
||||||
|
TARGET_VARIABLE = "appraisal_stressfulness"
|
||||||
|
print("TARGET_VARIABLE: " + TARGET_VARIABLE)
|
||||||
|
|
||||||
|
PATH_FULL = (
|
||||||
|
PATH_BASE
|
||||||
|
/ SEGMENT_LENGTH
|
||||||
|
/ ("input_" + TARGET_VARIABLE + "_" + SEGMENT_TYPE + "_mean.csv")
|
||||||
)
|
)
|
||||||
# model_input =
|
|
||||||
# model_input[model_input.columns.drop(
|
model_input = pd.read_csv(PATH_FULL)
|
||||||
# list(model_input.filter(regex='empatica_temperature'))
|
|
||||||
# )]
|
if SEGMENT_LENGTH == "daily":
|
||||||
# model_input = model_input[model_input['local_segment'].str.contains("daily")]
|
DAY_LENGTH = "daily" # or "working"
|
||||||
|
print(DAY_LENGTH)
|
||||||
|
model_input = model_input[model_input["local_segment"].str.contains(DAY_LENGTH)]
|
||||||
|
|
||||||
# %% jupyter={"outputs_hidden": false, "source_hidden": false}
|
# %% jupyter={"outputs_hidden": false, "source_hidden": false}
|
||||||
model_input["target"].value_counts()
|
model_input["target"].value_counts()
|
||||||
|
@ -63,7 +78,7 @@ model_input["target"], edges = pd.cut(
|
||||||
model_input.target, bins=bins, labels=["low", "high"], retbins=True, right=True
|
model_input.target, bins=bins, labels=["low", "high"], retbins=True, right=True
|
||||||
) # ['low', 'medium', 'high']
|
) # ['low', 'medium', 'high']
|
||||||
model_input["target"].value_counts(), edges
|
model_input["target"].value_counts(), edges
|
||||||
# model_input = model_input[model_input['target'] != "medium"]
|
model_input = model_input[model_input["target"] != "medium"]
|
||||||
model_input["target"] = (
|
model_input["target"] = (
|
||||||
model_input["target"].astype(str).apply(lambda x: 0 if x == "low" else 1)
|
model_input["target"].astype(str).apply(lambda x: 0 if x == "low" else 1)
|
||||||
)
|
)
|
||||||
|
@ -99,7 +114,7 @@ data_y.shape
|
||||||
scores = run_all_classification_models(data_x, data_y, data_groups, cross_validator)
|
scores = run_all_classification_models(data_x, data_y, data_groups, cross_validator)
|
||||||
# %%
|
# %%
|
||||||
scores.to_csv(
|
scores.to_csv(
|
||||||
"../presentation/appraisal_stressfulness_event_classification_"
|
"../presentation/results/appraisal_stressfulness_awake_classification_"
|
||||||
+ CV_METHOD
|
+ CV_METHOD
|
||||||
+ ".csv",
|
+ ".csv",
|
||||||
index=False,
|
index=False,
|
||||||
|
|
Loading…
Reference in New Issue