title: Grid Search with Recursive Feature Elimination in scikit-learn pipeline returns an error
body: <p>I am trying to chain Grid Search and Recursive Feature Elimination in a Pipeline using scikit-learn.</p>
  
  <p>GridSearchCV and RFE with "bare" classifier works fine:</p>
  
  <pre><code>from sklearn.datasets import make_friedman1
  from sklearn import feature_selection
  from sklearn.grid_search import GridSearchCV
  from sklearn.svm import SVR
  
  X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
  
  est = SVR(kernel="linear")
  
  selector = feature_selection.RFE(est)
  param_grid = dict(estimator__C=[0.1, 1, 10])
  clf = GridSearchCV(selector, param_grid=param_grid, cv=10)
  clf.fit(X, y)
  </code></pre>
  
  <p>Putting classifier in a pipeline returns an error: RuntimeError: The classifier does not expose "coef_" or "feature_importances_" attributes</p>
  
  <pre><code>from sklearn.datasets import make_friedman1
  from sklearn import feature_selection
  from sklearn import preprocessing
  from sklearn import pipeline
  from sklearn.grid_search import GridSearchCV
  from sklearn.svm import SVR
  
  X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
  
  est = SVR(kernel="linear")
  
  std_scaler = preprocessing.StandardScaler()
  pipe_params = [('std_scaler', std_scaler), ('clf', est)]
  pipe = pipeline.Pipeline(pipe_params)
  
  selector = feature_selection.RFE(pipe)
  param_grid = dict(estimator__clf__C=[0.1, 1, 10])
  clf = GridSearchCV(selector, param_grid=param_grid, cv=10)
  clf.fit(X, y)
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I have realised that I was not clear describing the problem. This is the clearer snippet:</p>
  
  <pre><code>from sklearn.datasets import make_friedman1
  from sklearn import feature_selection
  from sklearn import pipeline
  from sklearn.grid_search import GridSearchCV
  from sklearn.svm import SVR
  
  X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
  
  # This will work
  est = SVR(kernel="linear")
  selector = feature_selection.RFE(est)
  clf = GridSearchCV(selector, param_grid={'estimator__C': [1, 10]})
  clf.fit(X, y)
  
  # This will not work
  est = pipeline.make_pipeline(SVR(kernel="linear"))
  selector = feature_selection.RFE(est)
  clf = GridSearchCV(selector, param_grid={'estimator__svr__C': [1, 10]})
  clf.fit(X, y)
  </code></pre>
  
  <p>As you can see, the only difference is putting the estimator in a pipeline. Pipeline, however, hides "coef_" or "feature_importances_" attributes. The questions are:</p>
  
  <ol>
  <li>Is there a nice way of dealing with this in scikit-learn?</li>
  <li>If not, is this behaviour desired for any reason?</li>
  </ol>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>Updated, working snippet based on the answer provided by @Chris</p>
  
  <pre><code>from sklearn.datasets import make_friedman1
  from sklearn import feature_selection
  from sklearn import pipeline
  from sklearn.grid_search import GridSearchCV
  from sklearn.svm import SVR
  
  
  class MyPipe(pipeline.Pipeline):
  
      def fit(self, X, y=None, **fit_params):
          """Calls last elements .coef_ method.
          Based on the sourcecode for decision_function(X).
          Link: https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/pipeline.py
          ----------
          """
          super(MyPipe, self).fit(X, y, **fit_params)
          self.coef_ = self.steps[-1][-1].coef_
          return self
  
  
  X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
  
  # Without Pipeline
  est = SVR(kernel="linear")
  selector = feature_selection.RFE(est)
  clf = GridSearchCV(selector, param_grid={'estimator__C': [1, 10, 100]})
  clf.fit(X, y)
  print(clf.grid_scores_)
  
  # With Pipeline
  est = MyPipe([('svr', SVR(kernel="linear"))])
  selector = feature_selection.RFE(est)
  clf = GridSearchCV(selector, param_grid={'estimator__svr__C': [1, 10, 100]})
  clf.fit(X, y)
  print(clf.grid_scores_)
  </code></pre>