This example constructs a pipeline that does dimensionality reduction followed by prediction with a support vector classifier. It demonstrates the use of GridSearchCV
and Pipeline
to optimize over different classes of estimators in a single CV run – unsupervised PCA
and NMF
dimensionality reductions are compared to univariate feature selection during the grid search.
Additionally, Pipeline
can be instantiated with the memory
argument to memoize the transformers within the pipeline, avoiding to fit again the same transformers over and over.
Note that the use of memory
to enable caching becomes interesting when the fitting of a transformer is costly.
Pipeline
and GridSearchCV
Pipeline
with GridSearchCV
# Authors: Robert McGibbon, Joel Nothman, Guillaume Lemaitre from __future__ import print_function, division import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import load_digits from sklearn.model_selection import GridSearchCV from sklearn.pipeline import Pipeline from sklearn.svm import LinearSVC from sklearn.decomposition import PCA, NMF from sklearn.feature_selection import SelectKBest, chi2 print(__doc__) pipe = Pipeline([ ('reduce_dim', PCA()), ('classify', LinearSVC()) ]) N_FEATURES_OPTIONS = [2, 4, 8] C_OPTIONS = [1, 10, 100, 1000] param_grid = [ { 'reduce_dim': [PCA(iterated_power=7), NMF()], 'reduce_dim__n_components': N_FEATURES_OPTIONS, 'classify__C': C_OPTIONS }, { 'reduce_dim': [SelectKBest(chi2)], 'reduce_dim__k': N_FEATURES_OPTIONS, 'classify__C': C_OPTIONS }, ] reducer_labels = ['PCA', 'NMF', 'KBest(chi2)'] grid = GridSearchCV(pipe, cv=3, n_jobs=1, param_grid=param_grid) digits = load_digits() grid.fit(digits.data, digits.target) mean_scores = np.array(grid.cv_results_['mean_test_score']) # scores are in the order of param_grid iteration, which is alphabetical mean_scores = mean_scores.reshape(len(C_OPTIONS), -1, len(N_FEATURES_OPTIONS)) # select score for best C mean_scores = mean_scores.max(axis=0) bar_offsets = (np.arange(len(N_FEATURES_OPTIONS)) * (len(reducer_labels) + 1) + .5) plt.figure() COLORS = 'bgrcmyk' for i, (label, reducer_scores) in enumerate(zip(reducer_labels, mean_scores)): plt.bar(bar_offsets + i, reducer_scores, label=label, color=COLORS[i]) plt.title("Comparing feature reduction techniques") plt.xlabel('Reduced number of features') plt.xticks(bar_offsets + len(reducer_labels) / 2, N_FEATURES_OPTIONS) plt.ylabel('Digit classification accuracy') plt.ylim((0, 1)) plt.legend(loc='upper left')
Pipeline
It is sometimes worthwhile storing the state of a specific transformer since it could be used again. Using a pipeline in GridSearchCV
triggers such situations. Therefore, we use the argument memory
to enable caching.
Warning
Note that this example is, however, only an illustration since for this specific case fitting PCA is not necessarily slower than loading the cache. Hence, use the memory
constructor parameter when the fitting of a transformer is costly.
from tempfile import mkdtemp from shutil import rmtree from sklearn.externals.joblib import Memory # Create a temporary folder to store the transformers of the pipeline cachedir = mkdtemp() memory = Memory(cachedir=cachedir, verbose=10) cached_pipe = Pipeline([('reduce_dim', PCA()), ('classify', LinearSVC())], memory=memory) # This time, a cached pipeline will be used within the grid search grid = GridSearchCV(cached_pipe, cv=3, n_jobs=1, param_grid=param_grid) digits = load_digits() grid.fit(digits.data, digits.target) # Delete the temporary cache before exiting rmtree(cachedir)
Out:
________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(PCA(copy=True, iterated_power=7, n_components=2, random_state=None, svd_solver='auto', tol=0.0, whiten=False), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(PCA(copy=True, iterated_power=7, n_components=2, random_state=None, svd_solver='auto', tol=0.0, whiten=False), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(PCA(copy=True, iterated_power=7, n_components=2, random_state=None, svd_solver='auto', tol=0.0, whiten=False), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 4])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(PCA(copy=True, iterated_power=7, n_components=4, random_state=None, svd_solver='auto', tol=0.0, whiten=False), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(PCA(copy=True, iterated_power=7, n_components=4, random_state=None, svd_solver='auto', tol=0.0, whiten=False), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(PCA(copy=True, iterated_power=7, n_components=4, random_state=None, svd_solver='auto', tol=0.0, whiten=False), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 4])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(PCA(copy=True, iterated_power=7, n_components=8, random_state=None, svd_solver='auto', tol=0.0, whiten=False), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(PCA(copy=True, iterated_power=7, n_components=8, random_state=None, svd_solver='auto', tol=0.0, whiten=False), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(PCA(copy=True, iterated_power=7, n_components=8, random_state=None, svd_solver='auto', tol=0.0, whiten=False), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 4])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(NMF(alpha=0.0, beta_loss='frobenius', init=None, l1_ratio=0.0, max_iter=200, n_components=2, random_state=None, shuffle=False, solver='cd', tol=0.0001, verbose=0), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.1s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(NMF(alpha=0.0, beta_loss='frobenius', init=None, l1_ratio=0.0, max_iter=200, n_components=2, random_state=None, shuffle=False, solver='cd', tol=0.0001, verbose=0), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(NMF(alpha=0.0, beta_loss='frobenius', init=None, l1_ratio=0.0, max_iter=200, n_components=2, random_state=None, shuffle=False, solver='cd', tol=0.0001, verbose=0), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 4])) ________________________________________________fit_transform_one - 0.1s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(NMF(alpha=0.0, beta_loss='frobenius', init=None, l1_ratio=0.0, max_iter=200, n_components=4, random_state=None, shuffle=False, solver='cd', tol=0.0001, verbose=0), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.1s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(NMF(alpha=0.0, beta_loss='frobenius', init=None, l1_ratio=0.0, max_iter=200, n_components=4, random_state=None, shuffle=False, solver='cd', tol=0.0001, verbose=0), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.1s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(NMF(alpha=0.0, beta_loss='frobenius', init=None, l1_ratio=0.0, max_iter=200, n_components=4, random_state=None, shuffle=False, solver='cd', tol=0.0001, verbose=0), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 4])) ________________________________________________fit_transform_one - 0.1s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(NMF(alpha=0.0, beta_loss='frobenius', init=None, l1_ratio=0.0, max_iter=200, n_components=8, random_state=None, shuffle=False, solver='cd', tol=0.0001, verbose=0), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.1s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(NMF(alpha=0.0, beta_loss='frobenius', init=None, l1_ratio=0.0, max_iter=200, n_components=8, random_state=None, shuffle=False, solver='cd', tol=0.0001, verbose=0), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.1s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(NMF(alpha=0.0, beta_loss='frobenius', init=None, l1_ratio=0.0, max_iter=200, n_components=8, random_state=None, shuffle=False, solver='cd', tol=0.0001, verbose=0), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 4])) ________________________________________________fit_transform_one - 0.1s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/418724be7e0f221c63842489d2d8dd8f ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/3e8d95d340d603afdf4d48f022bf17e5 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/883d0a1cdb71638bbb069032713ce9dc ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/958eff19e89776bd76df5aa2c245d3da ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/ba78eb5c2dcd4d6aa3f6153ebf783541 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/42022a50c9fdba89266fe57fa5f8b6cd ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/7920cd319ba93f250d5f3618e3d15da7 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/9e042898790629dd460a8b6f9fef2fd4 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/55ce05e1fc3d79d04d79b8e2aacec9cf ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/16c841ed85ffdb4fee198a8f99f5c1f4 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/35bff840b1d192804fd4ff24064e96f2 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/77797263aafc1cb48306ec67242c6ad5 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/f0515fdac3406fc25644d355469c0533 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/c5cbf3ce208ba301242b09931977b0ba ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/02ad81983f20f4c5cf0d47056cdacf9e ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/8ac7812389fd8128d90760e78d84e3af ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/c832e7ce545bf8ed19c9646b7df57b94 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/5a7c149c4c779fcfb3e3b5d4859f28e5 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/418724be7e0f221c63842489d2d8dd8f ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/3e8d95d340d603afdf4d48f022bf17e5 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/883d0a1cdb71638bbb069032713ce9dc ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/958eff19e89776bd76df5aa2c245d3da ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/ba78eb5c2dcd4d6aa3f6153ebf783541 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/42022a50c9fdba89266fe57fa5f8b6cd ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/7920cd319ba93f250d5f3618e3d15da7 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/9e042898790629dd460a8b6f9fef2fd4 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/55ce05e1fc3d79d04d79b8e2aacec9cf ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/16c841ed85ffdb4fee198a8f99f5c1f4 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/35bff840b1d192804fd4ff24064e96f2 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/77797263aafc1cb48306ec67242c6ad5 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/f0515fdac3406fc25644d355469c0533 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/c5cbf3ce208ba301242b09931977b0ba ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/02ad81983f20f4c5cf0d47056cdacf9e ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/8ac7812389fd8128d90760e78d84e3af ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/c832e7ce545bf8ed19c9646b7df57b94 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/5a7c149c4c779fcfb3e3b5d4859f28e5 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/418724be7e0f221c63842489d2d8dd8f ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/3e8d95d340d603afdf4d48f022bf17e5 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/883d0a1cdb71638bbb069032713ce9dc ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/958eff19e89776bd76df5aa2c245d3da ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/ba78eb5c2dcd4d6aa3f6153ebf783541 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/42022a50c9fdba89266fe57fa5f8b6cd ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/7920cd319ba93f250d5f3618e3d15da7 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/9e042898790629dd460a8b6f9fef2fd4 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/55ce05e1fc3d79d04d79b8e2aacec9cf ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/16c841ed85ffdb4fee198a8f99f5c1f4 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/35bff840b1d192804fd4ff24064e96f2 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/77797263aafc1cb48306ec67242c6ad5 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/f0515fdac3406fc25644d355469c0533 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/c5cbf3ce208ba301242b09931977b0ba ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/02ad81983f20f4c5cf0d47056cdacf9e ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/8ac7812389fd8128d90760e78d84e3af ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/c832e7ce545bf8ed19c9646b7df57b94 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/5a7c149c4c779fcfb3e3b5d4859f28e5 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(SelectKBest(k=2, score_func=<function chi2 at 0x2b3aa35f6950>), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(SelectKBest(k=2, score_func=<function chi2 at 0x2b3aa35f6950>), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(SelectKBest(k=2, score_func=<function chi2 at 0x2b3aa35f6950>), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 4])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(SelectKBest(k=4, score_func=<function chi2 at 0x2b3aa35f6950>), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(SelectKBest(k=4, score_func=<function chi2 at 0x2b3aa35f6950>), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(SelectKBest(k=4, score_func=<function chi2 at 0x2b3aa35f6950>), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 4])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(SelectKBest(k=8, score_func=<function chi2 at 0x2b3aa35f6950>), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(SelectKBest(k=8, score_func=<function chi2 at 0x2b3aa35f6950>), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(SelectKBest(k=8, score_func=<function chi2 at 0x2b3aa35f6950>), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 4])) ________________________________________________fit_transform_one - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/5fe54eb7ee530b63acb3dfa6861e7e31 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/4a03a48a7aad7233e42fab570e812d55 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/ece18c14ce6fdfec2f6f7eac72d33d65 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/df50d8982a4424bfd6b6eb0cc9345085 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/4a3e478397b79f5dd3eac4d1ed5f18ff ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/86fd5ede2d28c646cee97060abe98fa2 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/e2dec44788d6d43bbacc041a12a5b694 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/598e66f4fb276b36069528d316e749ad ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/03b4bcf60a35f2c1b7169e05514a8b9f ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/5fe54eb7ee530b63acb3dfa6861e7e31 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/4a03a48a7aad7233e42fab570e812d55 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/ece18c14ce6fdfec2f6f7eac72d33d65 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/df50d8982a4424bfd6b6eb0cc9345085 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/4a3e478397b79f5dd3eac4d1ed5f18ff ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/86fd5ede2d28c646cee97060abe98fa2 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/e2dec44788d6d43bbacc041a12a5b694 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/598e66f4fb276b36069528d316e749ad ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/03b4bcf60a35f2c1b7169e05514a8b9f ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/5fe54eb7ee530b63acb3dfa6861e7e31 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/4a03a48a7aad7233e42fab570e812d55 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/ece18c14ce6fdfec2f6f7eac72d33d65 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/df50d8982a4424bfd6b6eb0cc9345085 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/4a3e478397b79f5dd3eac4d1ed5f18ff ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/86fd5ede2d28c646cee97060abe98fa2 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/e2dec44788d6d43bbacc041a12a5b694 ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/598e66f4fb276b36069528d316e749ad ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min [Memory] 0.0s, 0.0min: Loading _fit_transform_one from /tmp/tmpt93z6hvw/joblib/sklearn/pipeline/_fit_transform_one/03b4bcf60a35f2c1b7169e05514a8b9f ___________________________________fit_transform_one cache loaded - 0.0s, 0.0min ________________________________________________________________________________ [Memory] Calling sklearn.pipeline._fit_transform_one... _fit_transform_one(PCA(copy=True, iterated_power=7, n_components=8, random_state=None, svd_solver='auto', tol=0.0, whiten=False), None, array([[ 0., ..., 0.], ..., [ 0., ..., 0.]]), array([0, ..., 8])) ________________________________________________fit_transform_one - 0.0s, 0.0min
The PCA
fitting is only computed at the evaluation of the first configuration of the C
parameter of the LinearSVC
classifier. The other configurations of C
will trigger the loading of the cached PCA
estimator data, leading to save processing time. Therefore, the use of caching the pipeline using memory
is highly beneficial when fitting a transformer is costly.
plt.show()
Total running time of the script: ( 1 minutes 23.229 seconds)
© 2007–2017 The scikit-learn developers
Licensed under the 3-clause BSD License.
http://scikit-learn.org/stable/auto_examples/plot_compare_reduction.html