title: Custom pipeline for different data type in scikit learn
body: <p>I am currently trying to predict whether a kickstarter project will be successful or no depending on a bunch of integer and some text features. I was looking at building a pipeline which would look something like this</p>
  
  <p>Reference : <a href="http://scikit-learn.org/stable/auto_examples/hetero_feature_union.html#sphx-glr-auto-examples-hetero-feature-union-py" rel="nofollow noreferrer">http://scikit-learn.org/stable/auto_examples/hetero_feature_union.html#sphx-glr-auto-examples-hetero-feature-union-py</a></p>
  
  <p>Here is my ItemSelector and pipeline code</p>
  
  <pre><code>class ItemSelector(BaseEstimator, TransformerMixin):    
      def __init__(self, keys):
          self.keys = keys
  
      def fit(self, x, y=None):
          return self
  
      def transform(self, data_dict):
          return data_dict[self.keys]
  </code></pre>
  
  <p>I verified that the ItemSelector is working as expected by </p>
  
  <pre><code>t = ItemSelector(['cleaned_text'])
  t.transform(df)
  
  And it extract the necessary columns
  </code></pre>
  
  <h3>Pipeline</h3>
  
  <pre><code>pipeline = Pipeline([
      # Use FeatureUnion to combine the features from subject and body
      ('union', FeatureUnion(
          transformer_list=[
              # Pipeline for pulling features from the post's subject line
              ('text', Pipeline([
                  ('selector', ItemSelector(['cleaned_text'])),
                  ('counts', CountVectorizer()),
                  ('tf_idf', TfidfTransformer())
              ])),
  
              # Pipeline for pulling ad hoc features from post's body
              ('integer_features', ItemSelector(int_features)),
          ]
      )),
  
      # Use a SVC classifier on the combined features
      ('svc', SVC(kernel='linear')),
  ])
  </code></pre>
  
  <p>But when I run pipeline.fit(X_train, y_train) I receive this error. Any idea how to fix this?</p>
  
  <pre><code>---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-27-317e1c402966&gt; in &lt;module&gt;()
  ----&gt; 1 pipeline.fit(X_train, y_train)
  
  ~/Anaconda/anaconda/envs/ds/lib/python3.5/site-packages/sklearn/pipeline.py in fit(self, X, y, **fit_params)
      266             This estimator
      267         """
  --&gt; 268         Xt, fit_params = self._fit(X, y, **fit_params)
      269         if self._final_estimator is not None:
      270             self._final_estimator.fit(Xt, y, **fit_params)
  
  ~/Anaconda/anaconda/envs/ds/lib/python3.5/site-packages/sklearn/pipeline.py in _fit(self, X, y, **fit_params)
      232                 pass
      233             elif hasattr(transform, "fit_transform"):
  --&gt; 234                 Xt = transform.fit_transform(Xt, y, **fit_params_steps[name])
      235             else:
      236                 Xt = transform.fit(Xt, y, **fit_params_steps[name]) \
  
  ~/Anaconda/anaconda/envs/ds/lib/python3.5/site-packages/sklearn/pipeline.py in fit_transform(self, X, y, **fit_params)
      740         self._update_transformer_list(transformers)
      741         if any(sparse.issparse(f) for f in Xs):
  --&gt; 742             Xs = sparse.hstack(Xs).tocsr()
      743         else:
      744             Xs = np.hstack(Xs)
  
  ~/Anaconda/anaconda/envs/ds/lib/python3.5/site-packages/scipy/sparse/construct.py in hstack(blocks, format, dtype)
      456 
      457     """
  --&gt; 458     return bmat([blocks], format=format, dtype=dtype)
      459 
      460 
  
  ~/Anaconda/anaconda/envs/ds/lib/python3.5/site-packages/scipy/sparse/construct.py in bmat(blocks, format, dtype)
      577                                                     exp=brow_lengths[i],
      578                                                     got=A.shape[0]))
  --&gt; 579                     raise ValueError(msg)
      580 
      581                 if bcol_lengths[j] == 0:
  
  ValueError: blocks[0,:] has incompatible row dimensions. Got blocks[0,1].shape[0] == 81096, expected 1.
  </code></pre>