title: Sklearn - Pipeline with StandardScaler, PolynomialFeatures and Regression
body: <p>I have the following model which scales the data, then uses polynomial features and finally feeds the data into a regression model with regularization, like so:</p>
  <pre><code>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33) 
  
  scaler = StandardScaler()
  scaler.fit(X_train)
      
  X_train_scaled = scaler.transform(X_train)
  X_test_scaled = scaler.transform(X_test)
  
  polynomial = PolynomialFeatures(degree=3, include_bias=False)           
  polynomial.fit(X_train_scaled)
  
  X_train_model = polynomial.transform(X_train_scaled)
  X_test_model = polynomial.transform(X_test_scaled)
  
  reg_model = Ridge(alpha=alpha)
  reg_model.fit(X_train_model, y_train)
  
  y_pred_train_model = reg_model.predict(X_train_model)
  r2_train = r2_score(y_train, y_pred_train_model)
  
  y_pred_test_model = reg_model.predict(X_test_model)
  r2_test = r2_score(y_test, y_pred_test_model)
  </code></pre>
  <p>It works fine, but seems a bit cumbersome with many fits and transformations. I've heard about this <code>Pipeline()</code> method in <code>sklearn</code>. How can I use it above in order to simplify the process?</p>