I have the following piece of code - it is a train function for Logistic regression. I run sweeps to be able to compare hyperparameter tuning results. My issue is that I don't know how to incorporate StratifiedKFold to work with sweeps. I would appreciate it if someone can help me modify my code:
def train(
confing=None,
X_train = features_train,
y_train = labels_train,
X_test = features_test,
y_test = labels_test
):
with wandb.init(
project=WANDB_PROJECT_NAME,
entity="name",
config=config_defaults,
tags=['logistic regression', 'tf-idf', 'l2', 'class weight', 'C'],
notes='Logistic regression run with several regularizations and with either None penalty or l2 penalty, and ''balanced'' or pre-calculated class_weight.'
):
config = wandb.config
log_reg = LogisticRegression(
penalty=config.penalty,
C = config.C,
class_weight = config.class_weight
)
log_reg.fit(X_train, y_train)
y_pred = log_reg.predict(X_test)
y_proba = log_reg.predict_proba(X_test)
labels=list(map(str,y_labels['label'].unique()))
# Visualize single plot
cm = wandb.sklearn.plot_confusion_matrix(y_test, y_pred, labels)
score_f1 = f1_score(y_test, y_pred, average='weighted')
sm = wandb.sklearn.plot_summary_metrics(
log_reg, X_train, y_train, X_test, y_test)
roc = wandb.sklearn.plot_roc(y_test, y_proba)
wandb.log({
"f1-weighted-log-regr-1": score_f1,
"roc-log-regr-1": roc,
"conf-mat-log-regr-1": cm,
"summary-metrics-log-regr-1": sm
})
sweep_id = wandb.sweep(sweep_config, project="log-regr")
wandb.agent(sweep_id, function=train)