title: Can't pickle a module object while using Hyperopt for Logistic Regression
body: <p>I am trying to fine tune Logistic Regression using Hyperopt in Python. Please find the optimization function below:</p>
  
  <pre><code>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}
  </code></pre>
  
  <p>While running the algorithm, It is showing me the following error.</p>
  
  <pre class="lang-js prettyprint-override"><code>TypeError: can't pickle module objects
  
  TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-22-934e4c484469&gt; in &lt;module&gt;
        6 
        7 # Optimize
  ----&gt; 8 best = fmin(fn = objective, space = space, algo = tpe.suggest, max_evals = MAX_EVALS, trials = bayes_trials)
  
  &lt;ipython-input-20-d9ea5e676676&gt; 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)
  ----&gt; 9     score = cross_val_score(clf, X_train, y_train, cv=cv, scoring='f1_macro')
        10 
        11     # Extract the best score
  </code></pre>
  
  <p>How can I solve this problem?</p>