11
11
12
12
from collections import defaultdict
13
13
14
- from abc import ABCMeta , abstractmethod
15
-
16
14
import numpy as np
17
15
from scipy import sparse
18
16
19
- from .base import clone , BaseEstimator , TransformerMixin
17
+ from .base import clone , TransformerMixin
20
18
from .externals .joblib import Parallel , delayed , Memory
21
19
from .externals import six
22
20
from .utils import tosequence
@@ -35,7 +33,7 @@ class Pipeline(_BaseComposition):
35
33
Intermediate steps of the pipeline must be 'transforms', that is, they
36
34
must implement fit and transform methods.
37
35
The final estimator only needs to implement fit.
38
- The transformers in the pipeline can be cached using ``` memory`` argument.
36
+ The transformers in the pipeline can be cached using ``memory`` argument.
39
37
40
38
The purpose of the pipeline is to assemble several steps that can be
41
39
cross-validated together while setting different parameters.
@@ -527,13 +525,27 @@ def _name_estimators(estimators):
527
525
return list (zip (names , estimators ))
528
526
529
527
530
- def make_pipeline (* steps ):
528
+ def make_pipeline (* steps , ** kwargs ):
531
529
"""Construct a Pipeline from the given estimators.
532
530
533
531
This is a shorthand for the Pipeline constructor; it does not require, and
534
532
does not permit, naming the estimators. Instead, their names will be set
535
533
to the lowercase of their types automatically.
536
534
535
+ Parameters
536
+ ----------
537
+ *steps : list of estimators,
538
+
539
+ memory : Instance of joblib.Memory or string, optional (default=None)
540
+ Used to cache the fitted transformers of the pipeline. By default,
541
+ no caching is performed. If a string is given, it is the path to
542
+ the caching directory. Enabling caching triggers a clone of
543
+ the transformers before fitting. Therefore, the transformer
544
+ instance given to the pipeline cannot be inspected
545
+ directly. Use the attribute ``named_steps`` or ``steps`` to
546
+ inspect estimators within the pipeline. Caching the
547
+ transformers is advantageous when fitting is time consuming.
548
+
537
549
Examples
538
550
--------
539
551
>>> from sklearn.naive_bayes import GaussianNB
@@ -549,7 +561,11 @@ def make_pipeline(*steps):
549
561
-------
550
562
p : Pipeline
551
563
"""
552
- return Pipeline (_name_estimators (steps ))
564
+ memory = kwargs .pop ('memory' , None )
565
+ if kwargs :
566
+ raise TypeError ('Unknown keyword arguments: "{}"'
567
+ .format (list (kwargs .keys ())[0 ]))
568
+ return Pipeline (_name_estimators (steps ), memory = memory )
553
569
554
570
555
571
def _fit_one_transformer (transformer , X , y ):
0 commit comments