14
14
# chkoar
15
15
# License: BSD
16
16
17
- from collections import defaultdict
18
17
from warnings import warn
19
18
20
- from .base import BaseEstimator
21
19
from sklearn .externals import six
20
+ from sklearn import pipeline
22
21
from sklearn .utils import tosequence
23
22
from sklearn .utils .metaestimators import if_delegate_has_method
24
23
25
- __all__ = ['Pipeline' , 'FeatureUnion' ]
24
+ __all__ = ['Pipeline' ]
26
25
27
26
28
- class Pipeline (BaseEstimator ):
27
+ class Pipeline (pipeline . Pipeline ):
29
28
30
29
"""Pipeline of transforms and resamples with a final estimator.
31
30
@@ -111,30 +110,6 @@ def __init__(self, steps):
111
110
"'%s' (type %s) doesn't)"
112
111
% (estimator , type (estimator )))
113
112
114
- @property
115
- def _estimator_type (self ):
116
- return self .steps [- 1 ][1 ]._estimator_type
117
-
118
- def get_params (self , deep = True ):
119
- if not deep :
120
- return super (Pipeline , self ).get_params (deep = False )
121
- else :
122
- out = self .named_steps
123
- for name , step in six .iteritems (self .named_steps ):
124
- for key , value in six .iteritems (step .get_params (deep = True )):
125
- out ['%s__%s' % (name , key )] = value
126
-
127
- out .update (super (Pipeline , self ).get_params (deep = False ))
128
- return out
129
-
130
- @property
131
- def named_steps (self ):
132
- return dict (self .steps )
133
-
134
- @property
135
- def _final_estimator (self ):
136
- return self .steps [- 1 ][1 ]
137
-
138
113
# Estimator interface
139
114
140
115
def _pre_transform (self , X , y = None , ** fit_params ):
@@ -403,36 +378,6 @@ def score(self, X, y=None):
403
378
print Xt .shape
404
379
return self .steps [- 1 ][- 1 ].score (Xt , y )
405
380
406
- @property
407
- def classes_ (self ):
408
- return self .steps [- 1 ][- 1 ].classes_
409
-
410
- @property
411
- def _pairwise (self ):
412
- # check if first estimator expects pairwise input
413
- return getattr (self .steps [0 ][1 ], '_pairwise' , False )
414
-
415
-
416
- def _name_estimators (estimators ):
417
- """Generate names for estimators."""
418
-
419
- names = [type (estimator ).__name__ .lower () for estimator in estimators ]
420
- namecount = defaultdict (int )
421
- for est , name in zip (estimators , names ):
422
- namecount [name ] += 1
423
-
424
- for k , v in list (six .iteritems (namecount )):
425
- if v == 1 :
426
- del namecount [k ]
427
-
428
- for i in reversed (range (len (estimators ))):
429
- name = names [i ]
430
- if name in namecount :
431
- names [i ] += "-%d" % namecount [name ]
432
- namecount [name ] -= 1
433
-
434
- return list (zip (names , estimators ))
435
-
436
381
437
382
def make_pipeline (* steps ):
438
383
"""Construct a Pipeline from the given estimators.
@@ -454,4 +399,4 @@ def make_pipeline(*steps):
454
399
-------
455
400
p : Pipeline
456
401
"""
457
- return Pipeline (_name_estimators (steps ))
402
+ return Pipeline (pipeline . _name_estimators (steps ))
0 commit comments