diff --git a/maint_tools/test_docstrings.py b/maint_tools/test_docstrings.py index 7438f1651ba79..e8c39c148320f 100644 --- a/maint_tools/test_docstrings.py +++ b/maint_tools/test_docstrings.py @@ -12,7 +12,6 @@ "AdditiveChi2Sampler", "AffinityPropagation", "AgglomerativeClustering", - "BaggingClassifier", "BaggingRegressor", "BernoulliNB", "BernoulliRBM", diff --git a/sklearn/ensemble/_bagging.py b/sklearn/ensemble/_bagging.py index a00d200fb0c55..498f5a4eef40e 100644 --- a/sklearn/ensemble/_bagging.py +++ b/sklearn/ensemble/_bagging.py @@ -235,8 +235,7 @@ def __init__( self.verbose = verbose def fit(self, X, y, sample_weight=None): - """Build a Bagging ensemble of estimators from the training - set (X, y). + """Build a Bagging ensemble of estimators from the training set (X, y). Parameters ---------- @@ -256,6 +255,7 @@ def fit(self, X, y, sample_weight=None): Returns ------- self : object + Fitted estimator. """ return self._fit(X, y, self.max_samples, sample_weight=sample_weight) @@ -291,6 +291,7 @@ def _fit(self, X, y, max_samples=None, max_depth=None, sample_weight=None): Returns ------- self : object + Fitted estimator. """ random_state = check_random_state(self.random_state) @@ -605,18 +606,9 @@ class BaggingClassifier(ClassifierMixin, BaseBagging): `oob_decision_function_` might contain NaN. This attribute exists only when ``oob_score`` is True. - Examples + See Also -------- - >>> from sklearn.svm import SVC - >>> from sklearn.ensemble import BaggingClassifier - >>> from sklearn.datasets import make_classification - >>> X, y = make_classification(n_samples=100, n_features=4, - ... n_informative=2, n_redundant=0, - ... random_state=0, shuffle=False) - >>> clf = BaggingClassifier(base_estimator=SVC(), - ... n_estimators=10, random_state=0).fit(X, y) - >>> clf.predict([[0, 0, 0, 0]]) - array([1]) + BaggingRegressor : A Bagging regressor. References ---------- @@ -633,6 +625,19 @@ class BaggingClassifier(ClassifierMixin, BaseBagging): .. [4] G. Louppe and P. Geurts, "Ensembles on Random Patches", Machine Learning and Knowledge Discovery in Databases, 346-361, 2012. + + Examples + -------- + >>> from sklearn.svm import SVC + >>> from sklearn.ensemble import BaggingClassifier + >>> from sklearn.datasets import make_classification + >>> X, y = make_classification(n_samples=100, n_features=4, + ... n_informative=2, n_redundant=0, + ... random_state=0, shuffle=False) + >>> clf = BaggingClassifier(base_estimator=SVC(), + ... n_estimators=10, random_state=0).fit(X, y) + >>> clf.predict([[0, 0, 0, 0]]) + array([1]) """ def __init__( @@ -866,7 +871,6 @@ def decision_function(self, X): to the classes in sorted order, as they appear in the attribute ``classes_``. Regression and binary classification are special cases with ``k == 1``, otherwise ``k==n_classes``. - """ check_is_fitted(self)