title: Linear Regression with sklearn using categorical variables
body: <p>I am trying to run a usual linear regression in Python using sk-learn, but I have some categorical data that I don't know exactly how to handle, especially because I imported the data using pandas <code>read.csv()</code> and I have learned from previous experiences and reading that Pandas and sk-learn don't get along quite well (yet).</p>
  
  <p>My data looks like this:</p>
  
  <pre><code>Salary  AtBat   Hits    League  EastDivision
  475     315     81      1       0
  480     479     130     0       0
  500     496     141     1       1
  </code></pre>
  
  <p>I wanna predict Salary using AtBat, Hits, League and EastDivision, where League and EastDivision are categorical.</p>
  
  <p>If I import the data via numpy's <code>loadtext()</code> I get a numpy array which in theory I could use with sklearn, but when I use DictVectorizer I get an error. My code is:</p>
  
  <pre><code>import numpy as np
  from sklearn.feature_extraction import DictVectorizer as DV
  
  nphitters=np.loadtxt('Hitters.csv',delimiter=',', skiprows=1)
  vec = DV( sparse = False )
  catL=vec.fit_transform(nphitters[:,3:4])
  </code></pre>
  
  <p>And I get the error when I run the last line <code>catL=vec.fit_transform(nphitters[:,3:4])</code>, the error is </p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python2.7/dist-packages/sklearn/feature_extraction/dict_vectorizer.py", line 142, in fit_transform
      self.fit(X)
    File "/usr/lib/python2.7/dist-packages/sklearn/feature_extraction/dict_vectorizer.py", line 107, in fit
      for f, v in six.iteritems(x):
    File "/usr/lib/python2.7/dist-packages/sklearn/externals/six.py", line 268, in iteritems
      return iter(getattr(d, _iteritems)())
  AttributeError: 'numpy.ndarray' object has no attribute 'iteritems'
  </code></pre>
  
  <p>I don't know how to fix it, and another thing is, once I get the categorical data working, how do I run the regression? Just as if the categorical variable were another numeric variable?</p>
  
  <p>I have found several questions similar to mine, but none of them have really worked for me.</p>