title: Error using GridSearchCV but not without GridSearchCV - Python 3.6.7
body: <p>I am experiencing a weird bug where my code fails when using <code>GridSearchCV</code>, but not when just running <code>sklearnMLPRegressor</code> on its own.</p>
  
  <p>The following code:</p>
  
  <pre><code>from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
  from sklearn.neural_network import MLPRegressor
  from sklearn.model_selection import train_test_split
  from sklearn.neural_network import MLPRegressor
  from sklearn import preprocessing
  import pandas as pd
  import numpy as np
  
  def str_to_num(arr):
      le = preprocessing.LabelEncoder()
      new_arr = le.fit_transform(arr)
      return new_arr
  
  def compare_values(arr1, arr2):
      thediff = 0
      thediffs = []
      for thing1, thing2 in zip(arr1, arr2):
          thediff = abs(thing1 - thing2)
          thediffs.append(thediff)
  
      return thediffs
  
  def print_to_file(filepath, arr):
      with open(filepath, 'w') as f:
          for item in arr:
              f.write("%s\n" % item)
  
  data = pd.read_csv('data2.csv')
  
  # create the labels, or field we are trying to estimate
  label = data['TOTAL']
  # remove the header
  label = label[1:]
  
  # create the data, or the data that is to be estimated
  data = data.drop('TOTAL', axis=1)
  data = data.drop('SERIALNUM', axis=1)
  # remove the header
  data = data[1:]
  
  # # split into training and testing sets
  X_train, X_test, y_train, y_test = train_test_split(data, label, test_size = 0.2)
  
  mlp = MLPRegressor(activation = 'relu', solver = 'lbfgs', verbose=False)
  mlp.fit(X_train, y_train)
  mlp_predictions = mlp.predict(X_test)
  mlp_differences = compare_values(y_test, mlp_predictions)
  mlp_Avg = np.average(mlp_differences)
  print(mlp_Avg)
  </code></pre>
  
  <p>Prints the following:</p>
  
  <blockquote>
    <p>32.92041129078561
    <em>(Yes I know that average error is bad)</em></p>
  </blockquote>
  
  <p>However, when trying to optimize parameters, this same parameter setting yields an error:</p>
  
  <pre><code>from sklearn.neural_network import MLPRegressor
  from sklearn.model_selection import train_test_split, GridSearchCV
  from sklearn.neural_network import MLPRegressor
  from sklearn import preprocessing
  import pandas as pd
  import numpy as np
  
  
  def str_to_num(arr):
      le = preprocessing.LabelEncoder()
      new_arr = le.fit_transform(arr)
      return new_arr
  
  def compare_values(arr1, arr2):
      thediff = 0
      thediffs = []
      for thing1, thing2 in zip(arr1, arr2):
          thediff = abs(thing1 - thing2)
          thediffs.append(thediff)
  
      return thediffs
  
  def print_to_file(filepath, arr):
      with open(filepath, 'w') as f:
          for item in arr:
              f.write("%s\n" % item)
  
  data = pd.read_csv('data2.csv')
  
  # create the labels, or field we are trying to estimate
  label = data['TOTAL_DAYS_TO_COMPLETE']
  # remove the header
  label = label[1:]
  
  # create the data, or the data that is to be estimated
  data = data.drop('TOTAL_DAYS_TO_COMPLETE', axis=1)
  data = data.drop('SERIALNUM', axis=1)
  # remove the header
  data = data[1:]
  
  # # split into training and testing sets
  X_train, X_test, y_train, y_test = train_test_split(data, label, test_size = 0.2)
  
  param_grid = {
      #'hidden_layer_sizes': [(1,),(2,),(3,),(10,),(15,),(20,),(25,)],
      'activation': ['identity', 'logistic', 'relu'],
      #'activation': ['relu'],
      'solver': ['lbfgs', 'sgd', 'adam'],
      #'solver': ['adam']
      #'alpha': [0.0001, 0.0005, 0.0009],
      #'learning_rate': ['constant', 'invscaling', 'adaptive'],
      #'learning_rate_init': [0.001, 0.01, 0.99],
      #'warm_start': [True, False]
      #'momentum': [0.1, 0.9, 0.99]
      # Did not solver-specifics...yet
  }# Create a based model
  
  mlp = MLPRegressor()# Instantiate the grid search model
  grid_search = GridSearchCV(estimator = mlp, param_grid = param_grid, 
                            cv = 3, n_jobs = -1, verbose = 2)
  grid_search.fit(X_train, y_train)
  print()
  print(grid_search.best_params_)
  print(grid_search.best_score_)
  print()
  print("Grid scores on development set: ")
  print()
  answers = grid_search.predict(X_test)
  results = compare_values(answers, y_test)
  print("Accuracy: ", np.average(results))
  print()
  </code></pre>
  
  <p>Yields the following:</p>
  
  <blockquote>
    <p>Fitting 3 folds for each of 9 candidates, totalling 27 fits
    [Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent
    workers. [CV] activation=identity, solver=lbfgs
    ............................... [CV] activation=identity, solver=lbfgs
    ............................... [CV] activation=identity, solver=sgd
    .................................
    C:\Python367-64\lib\site-packages\sklearn\neural_network_base.py:195:
    RuntimeWarning: overflow encountered in square   return ((y_true -
    y_pred) ** 2).mean() / 2 [CV] activation=identity, solver=adam
    ................................ [CV] activation=identity,
    solver=lbfgs ............................... [CV] activation=identity,
    solver=sgd ................................. [CV] activation=identity,
    solver=sgd .................................</p>
    
    <p>&lt; removed extra lines that were working fine ></p>
    
    <p>!!! Here is where it starts to fail [CV] !!!! </p>
  </blockquote>
  
  <p>.................... activation=relu, solver=lbfgs, total=   0.5s</p>
  
  <blockquote>
    <p>joblib.externals.loky.process_executor._RemoteTraceback: """ Traceback
    (most recent call last):   File
    "C:\Python367-64\lib\site-packages\joblib\externals\loky\process_executor.py",
    line 418, in _process_worker
        r = call_item()   File "C:\Python367-64\lib\site-packages\joblib\externals\loky\process_executor.py",
    line 272, in <strong>call</strong>
        return self.fn(*self.args, **self.kwargs)   File "C:\Python367-64\lib\site-packages\joblib_parallel_backends.py", line
    567, in <strong>call</strong>
        return self.func(*args, **kwargs)   File "C:\Python367-64\lib\site-packages\joblib\parallel.py", line 225, in
    <strong>call</strong>
        for func, args, kwargs in self.items]   File "C:\Python367-64\lib\site-packages\joblib\parallel.py", line 225, in
    
        for func, args, kwargs in self.items]   File "C:\Python367-64\lib\site-packages\sklearn\model_selection_validation.py",
    line 554, in _fit_and_score
        test_scores = _score(estimator, X_test, y_test, scorer, is_multimetric)   File
    "C:\Python367-64\lib\site-packages\sklearn\model_selection_validation.py",
    line 597, in _score
        return _multimetric_score(estimator, X_test, y_test, scorer)   File
    "C:\Python367-64\lib\site-packages\sklearn\model_selection_validation.py",
    line 627, in _multimetric_score
        score = scorer(estimator, X_test, y_test)   File "C:\Python367-64\lib\site-packages\sklearn\metrics\scorer.py", line
    240, in _passthrough_scorer
        return estimator.score(*args, **kwargs)   File "C:\Python367-64\lib\site-packages\sklearn\base.py", line 410, in
    score
        y_type, _, _, _ = _check_reg_targets(y, y_pred, None)   File "C:\Python367-64\lib\site-packages\sklearn\metrics\regression.py",
    line 79, in _check_reg_targets
        y_pred = check_array(y_pred, ensure_2d=False)   File "C:\Python367-64\lib\site-packages\sklearn\utils\validation.py", line
    542, in check_array
        allow_nan=force_all_finite == 'allow-nan')   File "C:\Python367-64\lib\site-packages\sklearn\utils\validation.py", line
    56, in _assert_all_finite
        raise ValueError(msg_err.format(type_err, X.dtype)) ValueError: Input contains NaN, infinity or a value too large for
    dtype('float64'). """</p>
    
    <p>The above exception was the direct cause of the following exception:</p>
    
    <p>Traceback (most recent call last):   File "mlp_optimizer.py", line 93,
    in 
        grid_search.fit(X_train, y_train)   File "C:\Python367-64\lib\site-packages\sklearn\model_selection_search.py",
    line 687, in fit
        self._run_search(evaluate_candidates)   File "C:\Python367-64\lib\site-packages\sklearn\model_selection_search.py",
    line 1148, in _run_search
        evaluate_candidates(ParameterGrid(self.param_grid))   File "C:\Python367-64\lib\site-packages\sklearn\model_selection_search.py",
    line 666, in evaluate_candidates
        cv.split(X, y, groups)))   File "C:\Python367-64\lib\site-packages\joblib\parallel.py", line 934, in
    <strong>call</strong>
        self.retrieve()   File "C:\Python367-64\lib\site-packages\joblib\parallel.py", line 833, in
    retrieve
        self._output.extend(job.get(timeout=self.timeout))   File "C:\Python367-64\lib\site-packages\joblib_parallel_backends.py", line
    521, in wrap_future_result
        return future.result(timeout=timeout)   File "C:\Python367-64\lib\concurrent\futures_base.py", line 432, in result
        return self.__get_result()   File "C:\Python367-64\lib\concurrent\futures_base.py", line 384, in
    __get_result
        raise self._exception ValueError: Input contains NaN, infinity or a value too large for dtype('float64').</p>
  </blockquote>
  
  <p>Why would it work when not using <code>GridSearchCV</code>, but using <code>GridSearchCV</code> causes it to fail?</p>