|
26 | 26 | from sklearn.cluster import MiniBatchKMeans |
27 | 27 | from sklearn.metrics.pairwise import euclidean_distances |
28 | 28 | from sklearn.exceptions import ConvergenceWarning |
29 | | -from sklearn.utils.metaestimators import if_delegate_has_method |
| 29 | +from sklearn.utils.metaestimators import available_if |
30 | 30 |
|
31 | 31 | # Tool library in which we get robust mean estimators. |
32 | 32 | from .mean_estimators import median_of_means_blocked, block_mom, huber |
|
48 | 48 |
|
49 | 49 | LOSS_FUNCTIONS = { |
50 | 50 | "hinge": (Hinge,), |
51 | | - "log": (Log,), |
| 51 | + "log_loss": (Log,), |
52 | 52 | "squared_error": (SquaredLoss,), |
53 | 53 | "squared_loss": (SquaredLoss,), |
54 | 54 | "squared_hinge": (SquaredHinge,), |
@@ -114,8 +114,8 @@ class _RobustWeightedEstimator(BaseEstimator): |
114 | 114 | loss : string or callable, mandatory |
115 | 115 | Name of the loss used, must be the same loss as the one optimized in |
116 | 116 | base_estimator. |
117 | | - Classification losses supported : 'log', 'hinge', 'squared_hinge', |
118 | | - 'modified_huber'. If 'log', then the base_estimator must support |
| 117 | + Classification losses supported : 'log_loss', 'hinge', 'squared_hinge', |
| 118 | + 'modified_huber'. If 'log_loss', then the base_estimator must support |
119 | 119 | predict_proba. Regression losses supported : 'squared_error', 'huber'. |
120 | 120 | If callable, the function is used as loss function ro construct |
121 | 121 | the weights. |
@@ -501,7 +501,7 @@ def predict(self, X): |
501 | 501 | return self.base_estimator_.predict(X) |
502 | 502 |
|
503 | 503 | def _check_proba(self): |
504 | | - if self.loss != "log": |
| 504 | + if self.loss != "log_loss": |
505 | 505 | raise AttributeError( |
506 | 506 | "Probability estimates are not available for" |
507 | 507 | " loss=%r" % self.loss |
@@ -538,7 +538,13 @@ def score(self, X, y=None): |
538 | 538 | check_is_fitted(self, attributes=["base_estimator_"]) |
539 | 539 | return self.base_estimator_.score(X, y) |
540 | 540 |
|
541 | | - @if_delegate_has_method(delegate="base_estimator") |
| 541 | + def _estimator_has(attr): |
| 542 | + def check(self): |
| 543 | + return hasattr(self.base_estimator_, attr) |
| 544 | + |
| 545 | + return check |
| 546 | + |
| 547 | + @available_if(_estimator_has("decision_function")) |
542 | 548 | def decision_function(self, X): |
543 | 549 | """Predict using the linear model. For classifiers only. |
544 | 550 |
|
@@ -607,7 +613,7 @@ class RobustWeightedClassifier(BaseEstimator, ClassifierMixin): |
607 | 613 | (using the inter-quartile range), this tends to be conservative |
608 | 614 | (robust). |
609 | 615 |
|
610 | | - loss : string, None or callable, default="log" |
| 616 | + loss : string, None or callable, default="log_loss" |
611 | 617 | Classification losses supported : 'log', 'hinge', 'modified_huber'. |
612 | 618 | If 'log', then the base_estimator must support predict_proba. |
613 | 619 |
|
@@ -709,7 +715,7 @@ def __init__( |
709 | 715 | max_iter=100, |
710 | 716 | c=None, |
711 | 717 | k=0, |
712 | | - loss="log", |
| 718 | + loss="log_loss", |
713 | 719 | sgd_args=None, |
714 | 720 | multi_class="ovr", |
715 | 721 | n_jobs=1, |
@@ -809,7 +815,7 @@ def predict(self, X): |
809 | 815 | return self.base_estimator_.predict(X) |
810 | 816 |
|
811 | 817 | def _check_proba(self): |
812 | | - if self.loss != "log": |
| 818 | + if self.loss != "log_loss": |
813 | 819 | raise AttributeError( |
814 | 820 | "Probability estimates are not available for" |
815 | 821 | " loss=%r" % self.loss |
|
0 commit comments