title: RandomForestClassifier error 'object of type 'int' has no len()'
body: <p>I am writing a code? and got struggled with ''object of type 'int' has no len()''</p>
  
  <p>Here's the piece of the code</p>
  
  <pre><code>parameters = {'max_depth':range(3, 11, 2), 'class_weight':range(3, 11, 2), 'min_impurity_decrease':range(3, 11, 2), 'max_features':range(3, 11, 2)}
  knc = RandomForestClassifier()
  clf = GridSearchCV(knc, parameters)
  clf.fit(X_train, y_train)
  clf.best_estimator_
  </code></pre>
  
  <p>Here's the traceboard</p>
  
  <pre><code>TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-71-3f7bf4b64f84&gt; in &lt;module&gt;()
        4 knc = RandomForestClassifier()
        5 clf = GridSearchCV(knc, parameters)
  ----&gt; 6 clf.fit(X_train, y_train)
        7 clf.best_estimator_
  
  ~\Anaconda3\lib\site-packages\sklearn\model_selection\_search.py in fit(self, X, y, groups, **fit_params)
      637                                   error_score=self.error_score)
      638           for parameters, (train, test) in product(candidate_params,
  --&gt; 639                                                    cv.split(X, y, groups)))
      640 
      641         # if one choose to see train score, "out" will contain train score info
  
  ~\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py in __call__(self, iterable)
      777             # was dispatched. In particular this covers the edge
      778             # case of Parallel used with an exhausted iterator.
  --&gt; 779             while self.dispatch_one_batch(iterator):
      780                 self._iterating = True
      781             else:
  
  ~\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py in dispatch_one_batch(self, iterator)
      623                 return False
      624             else:
  --&gt; 625                 self._dispatch(tasks)
      626                 return True
      627 
  
  ~\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py in _dispatch(self, batch)
      586         dispatch_timestamp = time.time()
      587         cb = BatchCompletionCallBack(dispatch_timestamp, len(batch), self)
  --&gt; 588         job = self._backend.apply_async(batch, callback=cb)
      589         self._jobs.append(job)
      590 
  
  ~\Anaconda3\lib\site-packages\sklearn\externals\joblib\_parallel_backends.py in apply_async(self, func, callback)
      109     def apply_async(self, func, callback=None):
      110         """Schedule a func to be run"""
  --&gt; 111         result = ImmediateResult(func)
      112         if callback:
      113             callback(result)
  
  ~\Anaconda3\lib\site-packages\sklearn\externals\joblib\_parallel_backends.py in __init__(self, batch)
      330         # Don't delay the application, to avoid keeping the input
      331         # arguments in memory
  --&gt; 332         self.results = batch()
      333 
      334     def get(self):
  
  ~\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py in __call__(self)
      129 
      130     def __call__(self):
  --&gt; 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
      132 
      133     def __len__(self):
  
  ~\Anaconda3\lib\site-packages\sklearn\externals\joblib\parallel.py in &lt;listcomp&gt;(.0)
      129 
      130     def __call__(self):
  --&gt; 131         return [func(*args, **kwargs) for func, args, kwargs in self.items]
      132 
      133     def __len__(self):
  
  ~\Anaconda3\lib\site-packages\sklearn\model_selection\_validation.py in _fit_and_score(estimator, X, y, scorer, train, test, verbose, parameters, fit_params, return_train_score, return_parameters, return_n_test_samples, return_times, error_score)
      456             estimator.fit(X_train, **fit_params)
      457         else:
  --&gt; 458             estimator.fit(X_train, y_train, **fit_params)
      459 
      460     except Exception as e:
  
  ~\Anaconda3\lib\site-packages\sklearn\ensemble\forest.py in fit(self, X, y, sample_weight)
      271         self.n_outputs_ = y.shape[1]
      272 
  --&gt; 273         y, expanded_class_weight = self._validate_y_class_weight(y)
      274 
      275         if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:
  
  ~\Anaconda3\lib\site-packages\sklearn\ensemble\forest.py in _validate_y_class_weight(self, y)
      512                     class_weight = self.class_weight
      513                 expanded_class_weight = compute_sample_weight(class_weight,
  --&gt; 514                                                               y_original)
      515 
      516         return y, expanded_class_weight
  
  ~\Anaconda3\lib\site-packages\sklearn\utils\class_weight.py in compute_sample_weight(class_weight, y, indices)
      162             weight_k = compute_class_weight(class_weight_k,
      163                                             classes_full,
  --&gt; 164                                             y_full)
      165 
      166         weight_k = weight_k[np.searchsorted(classes_full, y_full)]
  
  ~\Anaconda3\lib\site-packages\sklearn\utils\class_weight.py in compute_class_weight(class_weight, classes, y)
       42         raise ValueError("classes should include all valid labels that can "
       43                          "be in y")
  ---&gt; 44     if class_weight is None or len(class_weight) == 0:
       45         # uniform class weights
       46         weight = np.ones(classes.shape[0], dtype=np.float64, order='C')
  
  TypeError: object of type 'int' has no len()
  </code></pre>