title: Error with Sci-Kit Learn SGD Algo - "Array contains NaN or infinity"
body: <p>I am getting an error stating "Array contains NaN or infinity". I have checked my data both train/test for missing values and there is nothing missing. </p>
  
  <p>It's possible I have the wrong interpretation of what "Array contains NaN or infinity" means.</p>
  
  <pre><code>import numpy as np
  from sklearn import linear_model
  from numpy import genfromtxt, savetxt
  
  def main():
      #create the training &amp; test sets, skipping the header row with [1:]
      dataset = genfromtxt(open('C:\\Users\\Owner\\training.csv','r'), delimiter=',')[0:50]    
      target = [x[0] for x in dataset]
      train = [x[1:50] for x in dataset]
      test = genfromtxt(open('C:\\Users\\Owner\\test.csv','r'), delimiter=',')[0:50]
  
      #create and train the SGD
      sgd = linear_model.SGDClassifier()
      sgd.fit(train, target)
      predictions = [x[1] for x in sgd.predict(test)]
  
      savetxt('C:\\Users\\Owner\\Desktop\\preds.csv', predictions, delimiter=',', fmt='%f')
  
  if __name__=="__main__":
      main()
  </code></pre>
  
  <p>I thought that the data type might be throwing the algo for a loop (they are floating-points).</p>
  
  <p>I know that SGD can handle floating-points so I am not sure if this setup is requiring me to declare the datatype. </p>
  
  <p>Such as one of the following:</p>
  
  <pre><code>&gt;&gt;&gt; dt = np.dtype('i4')   # 32-bit signed integer
  &gt;&gt;&gt; dt = np.dtype('f8')   # 64-bit floating-point number
  &gt;&gt;&gt; dt = np.dtype('c16')  # 128-bit complex floating-point number
  &gt;&gt;&gt; dt = np.dtype('a25')  # 25-character string
  </code></pre>
  
  <p>Below is the full error-message:</p>
  
  <pre><code>---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-62-af5537e7802b&gt; in &lt;module&gt;()
       19
       20 if __name__=="__main__":
  ---&gt; 21     main()
  
  &lt;ipython-input-62-af5537e7802b&gt; in main()
       13     #create and train the SGD
       14     sgd = linear_model.SGDClassifier()
  ---&gt; 15     sgd.fit(train, target)
       16     predictions = [x[1] for x in sgd.predict(test)]
       17
  
  C:\Anaconda\lib\site-packages\sklearn\linear_model\stochastic_gradient.pyc in fi
  t(self, X, y, coef_init, intercept_init, class_weight, sample_weight)
      518                          coef_init=coef_init, intercept_init=intercept_i
  nit,
      519                          class_weight=class_weight,
  --&gt; 520                          sample_weight=sample_weight)
      521
      522
  
  C:\Anaconda\lib\site-packages\sklearn\linear_model\stochastic_gradient.pyc in _f
  it(self, X, y, alpha, C, loss, learning_rate, coef_init, intercept_init, class_w
  eight, sample_weight)
      397             self.class_weight = class_weight
      398
  --&gt; 399         X = atleast2d_or_csr(X, dtype=np.float64, order="C")
      400         n_samples, n_features = X.shape
      401
  
  C:\Anaconda\lib\site-packages\sklearn\utils\validation.pyc in atleast2d_or_csr(X
  , dtype, order, copy)
      114     """
      115     return _atleast2d_or_sparse(X, dtype, order, copy, sparse.csr_matrix
  ,
  --&gt; 116                                 "tocsr")
      117
      118
  
  C:\Anaconda\lib\site-packages\sklearn\utils\validation.pyc in _atleast2d_or_spar
  se(X, dtype, order, copy, sparse_class, convmethod)
       94         _assert_all_finite(X.data)
       95     else:
  ---&gt; 96         X = array2d(X, dtype=dtype, order=order, copy=copy)
       97         _assert_all_finite(X)
       98     return X
  
  C:\Anaconda\lib\site-packages\sklearn\utils\validation.pyc in array2d(X, dtype,
  order, copy)
       79                         'is required. Use X.toarray() to convert to dens
  e.')
       80     X_2d = np.asarray(np.atleast_2d(X), dtype=dtype, order=order)
  ---&gt; 81     _assert_all_finite(X_2d)
       82     if X is X_2d and copy:
       83         X_2d = safe_copy(X_2d)
  
  C:\Anaconda\lib\site-packages\sklearn\utils\validation.pyc in _assert_all_finite
  (X)
       16     if (X.dtype.char in np.typecodes['AllFloat'] and not np.isfinite(X.s
  um())
       17             and not np.isfinite(X).all()):
  ---&gt; 18         raise ValueError("Array contains NaN or infinity.")
       19
       20
  
  ValueError: Array contains NaN or infinity.
  </code></pre>
  
  <p>Any thoughts would be appreciated.</p>