title: Scikit-learn - ValueError: Input contains NaN, infinity or a value too large for dtype('float32') with Random Forest
body: <p>First, I have checked the different posts concerning this error and none of them can solve my issue.</p>
  <p>So I am using RandomForest and I am able to generate the forest and to do a prediction but sometimes during the generation of the forest, I get the following error.</p>
  <blockquote>
  <p>ValueError: Input contains NaN, infinity or a value too large for dtype('float32').</p>
  </blockquote>
  <p>This error occurs with the same dataset. Sometimes the dataset creates an error during the training and most of the time not. The error sometimes occurs at the start and sometimes in the middle of the training.</p>
  <p>Here's my code :</p>
  <pre><code>import pandas as pd
  from sklearn import ensemble
  import numpy as np
  
  def azureml_main(dataframe1 = None, dataframe2 = None):
  
      # Execution logic goes here
  
      Input = dataframe1.values[:,:]
      InputData = Input[:,:15]
      InputTarget = Input[:,16:]
  
      limitTrain = 2175
  
      clf = ensemble.RandomForestClassifier(n_estimators = 10000, n_jobs = 4 );
  
      features=np.empty([len(InputData),10])
      j=0
      for i in range (0,14):
          if (i == 1 or i == 4 or i == 5 or i == 6 or i == 8 or i == 9 or  i == 10 or i == 11 or i == 13 or i == 14):
              features[:,j] = (InputData[:, i])
              j += 1     
          
      clf.fit(features[:limitTrain,:],np.asarray(InputTarget[:limitTrain,1],dtype = np.float32))
  
      res = clf.predict_proba(features[limitTrain+1:,:])
  
      listreu = np.empty([len(res),5])
      for i in range(len(res)):
          if(res[i,0] &gt; 0.5):
              listreu[i,4] = 0;
          elif(res[i,1] &gt; 0.5):
              listreu[i,4] = 1;
          elif(res[i,2] &gt; 0.5):
              listreu[i,4] = 2;
          else:
              listreu[i,4] = 3;
      
  
      listreu[:,0] = features[limitTrain+1:,0]
      listreu[:,1] = InputData[limitTrain+1:,2]
      listreu[:,2] = InputData[limitTrain+1:,3]
      listreu[:,3] = features[limitTrain+1:,1]
  
  
  
      # Return value must be of a sequence of pandas.DataFrame
      return pd.DataFrame(listreu),
  </code></pre>
  <p>I ran my code locally and on <code>Azure ML</code> Studio and the error occurs in both cases.</p>
  <p>I am sure that it is not due to my dataset since most of the time I don't get the error and I am generating the dataset myself from different input.</p>
  <p>This is a <a href="http://%20https://pastebin.com/mC76uq8P" rel="nofollow noreferrer">part of the dataset I use</a></p>
  <p><strong>EDIT:</strong> I probably found out that I had 0 value which were not real 0 value. The values were like</p>
  <blockquote>
  <p>3.0x10^-314</p>
  </blockquote>