code: def next(
      self, grid, values, durations, candidates, pending, complete
  ):
      # Grab out the relevant sets.
  
      # Don't bother using fancy RF stuff at first.
      if complete.shape[0] < 2:
          return int(candidates[0])
  
      # Grab out the relevant sets.
      comp = grid[complete, :]
      cand = grid[candidates, :]
      pend = grid[pending, :]
      vals = values[complete]
  
      self.rf.fit(comp, vals)
  
      if pend.shape[0] != 0:
          # Generate fantasies for pending
          func_m, func_v = self.rf.predict(pend)
          vals_pend = (
              func_m + np.sqrt(func_v) + npr.randn(func_m.shape[0])
          )
  
          # Re-fit using fantasies
          self.rf.fit(np.vstack[comp, pend], np.hstack[vals, vals_pend])
  
          # Predict the marginal means and variances at candidates.
      func_m, func_v = self.rf.predict(cand)
  
      # Current best.
      best = np.min(vals)
  
      # Expected improvement
      func_s = np.sqrt(func_v) + 0.0001
      u = (best - func_m) / func_s
      ncdf = sps.norm.cdf(u)
      npdf = sps.norm.pdf(u)
      ei = func_s * (u * ncdf + npdf)
  
      best_cand = np.argmax(ei)
      ei.sort()
  
      return int(candidates[best_cand])
  
file_path: auptimizer/src/aup/Proposer/spearmint/chooser/RandomForestEIChooser.py
imports: import numpy
  import numpy.random
  import scipy.stats
  import sklearn.ensemble
  import sklearn.ensemble.forest
  from ..None import util
  import logging
  from sklearn.externals.joblib import Parallel, delayed
label_desc: Use image node_id 2 for calling the RandomForestEIChooser obj's underlying member method code with example usage: obj.next(grid, values, durations, candidates, pending, complete) and returns: int, int