title: Is there a way to store pipeline stages in sklearn?
body: <p>I am about to create a simple model-pipeline using sklearn´s pipeline module:</p>
  <pre><code>from sklearn.feature_extraction.text import TfidfVectorizer
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.decomposition import TruncatedSVD
  from sklearn.linear_model import LogisticRegression
  
  class TextTransformer(BaseEstimator, TransformerMixin):
      def __init__(self, key):
          self.key = key
  
      def fit(self, X, y=None, *parg, **kwarg):
          return self
  
      def transform(self, X):
          return X[self.key]
  
  X_train, X_test, y_train, y_test = train_test_split(df[['text']], 
                                                          df['target'],
                                                          test_size=0.20) 
  feature_pipeline =  Pipeline([
              ('transformer', TextTransformer(key='text')),
              ('tfidf', TfidfVectorizer(ngram_range=(1,1))),
              ('svd', TruncatedSVD(algorithm='randomized', n_components=150))
              ])
  
  pickle.dump(feature_pipeline, open(../&quot;.pkl&quot;, 'wb'))
  </code></pre>
  <p>After initializing the feature selection, <code>feature_pipeline</code>, I´d like to call the created pipe on several models from other scripts, like (SVC as an example):</p>
  <pre><code>svc_pipeline = Pipeline([('features', feature_pipeline),
                        ('SVC',SVC())
                        ])
  parameter_grid = {'SVC__kernel':['linear','rbf'],
                        'SVC__C':loguniform(1e-1, 1e2), 
                        'SVC__gamma':loguniform(1e-3, 1e0)}
  svc_pipeline = RandomizedSearchCV(svc_pipeline, parameter_grid, n_iter = 10, cv=5,n_jobs = -1))
  
  svc_pipeline.fit(X_train, y_train)
  predictions = svc_pipeline.predict(X_test)
  
  </code></pre>
  <p>So far, I´ve initialized each model in the same fashion and I´d assume the <code>feature_pipeline</code> has to be initialized for each model separately?!</p>
  <p>As a workaround, I currently pickle the fitted <code>feature_pipeline</code>, transform and store the X_train, X_test matrices, like:</p>
  <pre><code>feature_pipeline.fit(X_train)
  pickle.dump(feature_pipeline, open(../&quot;.pkl&quot;, 'wb'))
  
  X_train_transformed = feature_pipeline.transform(X_train)
  pickle.dump(X_train_transformed, open(../&quot;.pkl&quot;, 'wb'))
  
  X_test_transformed = feature_pipeline.transform(X_test)
  pickle.dump(X_test_transformed, open(../&quot;.pkl&quot;, 'wb'))
  
  
  </code></pre>
  <p>Is there a way to save the <code>feature_pipeline</code> directly so that it can be utilized without the need of applying this workaround? Or is there any other best practice?</p>