# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 2
#     language: python
#     name: python2
# ---

Putting it all together with Pipelines

from sklearn.datasets import load_iris
from sklearn.datasets import load_iris
import numpy as np
iris = load_iris()
iris_data = iris.data
mask = np.random.binomial(1, .25, iris_data.shape).astype(bool)
iris_data[mask] = np.nan
iris_data[:5]

# +
from sklearn import pipeline, preprocessing, decomposition


pca = decomposition.PCA()
imputer = preprocessing.Imputer()


pipe = pipeline.Pipeline([('imputer', imputer), ('pca', pca)])
iris_data_transformed = pipe.fit_transform(iris_data)
iris_data_transformed[:5]
# -

pipe2 = pipeline.make_pipeline(imputer, pca)
pipe2.steps

iris_data_transformed2 = pipe2.fit_transform(iris_data)
iris_data_transformed2[:5]

pipe2.set_params(pca__n_components=2)

iris_data_transformed3 = pipe2.fit_transform(iris_data)
iris_data_transformed3[:5]

StarcoderdataJupyterScriptsDedupFiltered