Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting to scikit-learn 1.5.0 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions skclean/handlers/example_weighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class WeightedBagging(BaggingClassifier):
Parameters
------------------
classifier: object
A classifier instance supporting sklearn API. Same as `base_estimator`
A classifier instance supporting sklearn API. Same as `estimator`
of scikit-learn's BaggingClassifier.

detector : `BaseDetector` or None, default=None
Expand Down Expand Up @@ -124,7 +124,7 @@ def __init__(self,
verbose=0):
BaggingClassifier.__init__(
self,
base_estimator=classifier,
estimator=classifier,
warm_start=False,
n_estimators=n_estimators,
n_jobs=n_jobs,
Expand All @@ -139,16 +139,16 @@ def __init__(self,

@property
def classifier(self):
return self.base_estimator
return self.estimator

@classifier.setter
def classifier(self, clf):
self.base_estimator = clf
self.estimator = clf


def _validate_estimator(self, default=DecisionTreeClassifier()):
super()._validate_estimator()
self.base_estimator_ = _WBBase(self.base_estimator_, self.replacement, self.sampling_ratio, self.conf_score_)
self.estimator_ = _WBBase(self.estimator_, self.replacement, self.sampling_ratio, self.conf_score_)

def fit(self, X, y, conf_score=None, **kwargs):
X, y, conf_score = _check_data_params(self, X, y, conf_score)
Expand Down Expand Up @@ -194,7 +194,7 @@ class Costing(BaggingClassifier):
Parameters
------------------
classifier: object
A classifier instance supporting sklearn API. Same as `base_estimator`
A classifier instance supporting sklearn API. Same as `estimator`
of scikit-learn's BaggingClassifier.

detector : `BaseDetector` or None, default=None
Expand Down Expand Up @@ -224,7 +224,7 @@ def __init__(self,
verbose=0):
BaggingClassifier.__init__(
self,
base_estimator=classifier,
estimator=classifier,
n_estimators=n_estimators,
warm_start=False,
n_jobs=n_jobs,
Expand All @@ -237,15 +237,15 @@ def __init__(self,

@property
def classifier(self):
return self.base_estimator
return self.estimator

@classifier.setter
def classifier(self, clf):
self.base_estimator = clf
self.estimator = clf

def _validate_estimator(self, default=DecisionTreeClassifier()):
super()._validate_estimator()
self.base_estimator_ = _RSBase(self.base_estimator_, self.conf_score_)
self.estimator_ = _RSBase(self.estimator_, self.conf_score_)

# Duplicate fit
def fit(self, X, y, conf_score=None, **kwargs):
Expand Down
12 changes: 9 additions & 3 deletions skclean/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

from sklearn import pipeline as skpipeline
from sklearn.base import clone
from sklearn.utils import _print_elapsed_time
from sklearn.utils.metaestimators import if_delegate_has_method
from sklearn.utils._user_interface import _print_elapsed_time
from sklearn.utils.metaestimators import available_if
from sklearn.utils.validation import check_memory

__all__ = ["Pipeline", "make_pipeline"]
Expand Down Expand Up @@ -214,7 +214,13 @@ def fit_transform(self, X, y=None, **fit_params):
else:
return last_step.fit(Xt, yt, **fit_params_last).transform(Xt)

@if_delegate_has_method(delegate="_final_estimator")
def _estimator_has(attr):
def check(self):
return hasattr(self.estimator, attr)

return check

@available_if(_estimator_has("_final_estimator"))
def fit_predict(self, X, y=None, **fit_params):
"""Apply `fit_predict` of last step in pipeline after transforms.

Expand Down