Skip to content

Commit d2b6102

Browse files
chkoarchkoar
authored andcommitted
Inherit from sklearn.pipeline.Pipeline instead of copy.
1 parent 567ef55 commit d2b6102

File tree

1 file changed

+4
-59
lines changed

1 file changed

+4
-59
lines changed

unbalanced_dataset/pipeline.py

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@
1414
# chkoar
1515
# License: BSD
1616

17-
from collections import defaultdict
1817
from warnings import warn
1918

20-
from .base import BaseEstimator
2119
from sklearn.externals import six
20+
from sklearn import pipeline
2221
from sklearn.utils import tosequence
2322
from sklearn.utils.metaestimators import if_delegate_has_method
2423

25-
__all__ = ['Pipeline', 'FeatureUnion']
24+
__all__ = ['Pipeline']
2625

2726

28-
class Pipeline(BaseEstimator):
27+
class Pipeline(pipeline.Pipeline):
2928

3029
"""Pipeline of transforms and resamples with a final estimator.
3130
@@ -111,30 +110,6 @@ def __init__(self, steps):
111110
"'%s' (type %s) doesn't)"
112111
% (estimator, type(estimator)))
113112

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-
138113
# Estimator interface
139114

140115
def _pre_transform(self, X, y=None, **fit_params):
@@ -403,36 +378,6 @@ def score(self, X, y=None):
403378
print Xt.shape
404379
return self.steps[-1][-1].score(Xt, y)
405380

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-
436381

437382
def make_pipeline(*steps):
438383
"""Construct a Pipeline from the given estimators.
@@ -454,4 +399,4 @@ def make_pipeline(*steps):
454399
-------
455400
p : Pipeline
456401
"""
457-
return Pipeline(_name_estimators(steps))
402+
return Pipeline(pipeline._name_estimators(steps))

0 commit comments

Comments
 (0)