title: Sklearn ValueError: Input contains NaN, infinity or a value too large for dtype('float32')
body: <p>I fit the following pipeline classifier:</p>
  <pre><code>Pipeline(memory=None,steps=[('scaler', MinMaxScaler(copy=True, feature_range=(0, 1))),
                     ('kbest', SelectKBest(k=1218,score_func=&lt;function mutual_info_classif at 0x7fec1e4991f0&gt;)),
                     ('classifier',RandomForestClassifier(bootstrap=True, ccp_alpha=0.0,
                                             class_weight='balanced_subsample',
                                             criterion='gini', max_depth=15,
                                             max_features='log2',
                                             max_leaf_nodes=5, max_samples=0.6,
                                             min_impurity_decrease=0.0,
                                             min_impurity_split=None,
                                             min_samples_leaf=2,
                                             min_samples_split=15,
                                             min_weight_fraction_leaf=0.0,
                                             n_estimators=50, n_jobs=None,
                                             oob_score=True, random_state=42,
                                             verbose=0, warm_start=False))],verbose=False)
  </code></pre>
  <p>It fits fine, but when I use predict on my test data I get a ValueError:</p>
  <blockquote>
  <p>*** ValueError: Input contains NaN, infinity or a value too large for dtype('float32').</p>
  </blockquote>
  <p>I checked for infinite and NaNs. The function raising the error is _assert_all_finite located in sklearn.utils.validation.py. I imported the function directly and ran it on the X_test array and got no errors:</p>
  <pre><code>from sklearn.utils import validation
  validation._assert_all_finite(X_test)
  </code></pre>
  <p>How can I get an error with the exact same data when I run the predict method on the classifier? It clearly doesn't have any NaNs or Infs or it would raise an error when I directly import the function. Somewhere along the predict method, it creates those values, but I don't know when, where and why... Any help would be much appreciated!</p>
  <p>Here's the full error message:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;testz.py&quot;, line 159, in &lt;module&gt;
      testing(dx_type, population, dx_option, feat_sel_metric, data_types, ratio_name, model_selection_metric, repo_path)
    File &quot;testz.py&quot;, line 107, in testing
      y_test_pred=top_clf.predict(X_test)
    File &quot;/home/user/anaconda3/envs/myenv/lib/python3.8/site-packages/sklearn/utils/metaestimators.py&quot;, line 116, in &lt;lambda&gt;
      out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs)
    File &quot;/home/user/anaconda3/envs/myenv/lib/python3.8/site-packages/sklearn/pipeline.py&quot;, line 420, in predict
      return self.steps[-1][-1].predict(Xt, **predict_params)
    File &quot;/home/user/anaconda3/envs/myenv/lib/python3.8/site-packages/sklearn/ensemble/_forest.py&quot;, line 612, in predict
      proba = self.predict_proba(X)
    File &quot;/home/user/anaconda3/envs/myenv/lib/python3.8/site-packages/sklearn/ensemble/_forest.py&quot;, line 656, in predict_proba
      X = self._validate_X_predict(X)
    File &quot;/home/user/anaconda3/envs/myenv/lib/python3.8/site-packages/sklearn/ensemble/_forest.py&quot;, line 412, in _validate_X_predict
      return self.estimators_[0]._validate_X_predict(X, check_input=True)
    File &quot;/home/user/anaconda3/envs/myenv/lib/python3.8/site-packages/sklearn/tree/_classes.py&quot;, line 380, in _validate_X_predict
      X = check_array(X, dtype=DTYPE, accept_sparse=&quot;csr&quot;)
    File &quot;/home/user/anaconda3/envs/myenv/lib/python3.8/site-packages/sklearn/utils/validation.py&quot;, line 577, in check_array
      _assert_all_finite(array,
    File &quot;/home/user/anaconda3/envs/myenv/lib/python3.8/site-packages/sklearn/utils/validation.py&quot;, line 57, in _assert_all_finite
      raise ValueError(
  ValueError: Input contains NaN, infinity or a value too large for dtype('float32').
  </code></pre>