Я пытаюсь настроить Logisti c Regression с помощью Hyperopt в Python. Найдите функцию оптимизации ниже:
def objective(params, n_folds = N_FOLDS):
"""Objective function for Logistic Regression Hyperparameter Tuning"""
# Perform n_fold cross validation with hyperparameters
# Use early stopping and evaluate based on ROC AUC
clf = LogisticRegression(**params,random_state=0,verbose =0)
cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1)
score = cross_val_score(clf, X_train, y_train, cv=cv, scoring='f1_macro')
# Extract the best score
best_score = max(score)
# Loss must be minimized
loss = 1 - best_score
# Dictionary with information for evaluation
return {'loss': loss, 'params': params, 'status': STATUS_OK}
При запуске алгоритма отображается следующая ошибка.
TypeError: can't pickle module objects
TypeError Traceback (most recent call last)
<ipython-input-22-934e4c484469> in <module>
6
7 # Optimize
----> 8 best = fmin(fn = objective, space = space, algo = tpe.suggest, max_evals = MAX_EVALS, trials = bayes_trials)
<ipython-input-20-d9ea5e676676> in objective(params, n_folds)
7 clf = LogisticRegression(**params,random_state=0,verbose =0)
8 cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1)
----> 9 score = cross_val_score(clf, X_train, y_train, cv=cv, scoring='f1_macro')
10
11 # Extract the best score
Как я могу решить эту проблему?