title: How to build re-usable scikit-learn pipeline for Random Forest Classifier?
body: <p>I am trying to understand how scikit-learn pipelines work. I have some dummy data and I am trying to fit a Random Forest model to iris data. Here is some code</p>
  <pre><code>from sklearn import datasets
  from sklearn import svm
  from sklearn.feature_selection import SelectKBest
  from sklearn.feature_selection import chi2
  from sklearn.ensemble import RandomForestClassifier
  from sklearn.pipeline import Pipeline
  from sklearn.model_selection import train_test_split
  import sklearn.externals
  import joblib
  from sklearn.datasets import make_classification
  from sklearn.svm import SVC
  from sklearn.preprocessing import StandardScaler
  # Load the Iris dataset
  iris = datasets.load_iris()
  </code></pre>
  <p>Divide data into train and test and create a pipeline with 2 steps</p>
  <pre><code>X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target,random_state=0)
  print(X_train.shape, X_test.shape, y_train.shape, y_test.shape)
  pipeline = Pipeline([('feature_selection', SelectKBest(chi2, k=2)), ('classification', RandomForestClassifier()) ])
  print(type(pipeline))
  (112, 4) (38, 4) (112,) (38,)
  &lt;class 'sklearn.pipeline.Pipeline'&gt;
  </code></pre>
  <p>But when i execute <code>pipeline.fit_transform(X_train, y_train)</code> , I get an error saying <code>AttributeError: 'RandomForestClassifier' object has no attribute 'transform'</code></p>
  <p>However, <code>pipeline.fit(X_train, y_train)</code> works fine.</p>
  <p>In a normal case scenario, without any <code>pipeline</code> code, what i have usually done is taken a ML model and applied <code>fit_transform()</code> on my <code>training</code> dataset and <code>transform</code> on my <code>unseen dataset</code> for generating predictions.</p>
  <p>How do I set something similar using pipelines in <code>sklearn</code>. I want to SAVE my pipeline and then perform scoring by LOADING it back? Can I do it using <code>pickle</code>?</p>
  <p>Another thing is regarding the RF model itself. I can get model summary using RF model methods but I dont see any methods in my pipeline where I can print model summary using <code>pipeline</code>.</p>