8000 [MRG] Add an example for ensemble.BaggingRegressor (#15196) · jeremiedbb/scikit-learn@bc3a7e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc3a7e1

Browse files
steinfurtqinhanmin2014
authored andcommitted
[MRG] Add an example for ensemble.BaggingRegressor (scikit-learn#15196)
1 parent 9b0d02d commit bc3a7e1

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

sklearn/ensemble/_bagging.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,14 +546,11 @@ class BaggingClassifier(ClassifierMixin, BaseBagging):
546546
>>> from sklearn.svm import SVC
547547
>>> from sklearn.ensemble import BaggingClassifier
548548
>>> from sklearn.datasets import make_classification
549-
>>> X, y = make_classification(n_samples=1000, n_features=4,
549+
>>> X, y = make_classification(n_samples=100, n_features=4,
550550
... n_informative=2, n_redundant=0,
551551
... random_state=0, shuffle=False)
552-
>>> clf = BaggingClassifier(n_estimators=100, random_state=0).fit(X, y)
553-
>>> clf.predict([[0, 0, 0, 0]])
554-
array([1])
555552
>>> clf = BaggingClassifier(base_estimator=SVC(),
556-
... n_estimators=100, random_state=0).fit(X, y)
553+
... n_estimators=10, random_state=0).fit(X, y)
557554
>>> clf.predict([[0, 0, 0, 0]])
558555
array([1])
559556
@@ -935,6 +932,19 @@ class BaggingRegressor(RegressorMixin, BaseBagging):
935932
`oob_prediction_` might contain NaN. This attribute exists only
936933
when ``oob_score`` is True.
937934
935+
Examples
936+
--------
937+
>>> from sklearn.svm import SVR
938+
>>> from sklearn.ensemble import BaggingRegressor
939+
>>> from sklearn.datasets import make_regression
940+
>>> X, y = make_regression(n_samples=100, n_features=4,
941+
... n_informative=2, n_targets=1,
942+
... random_state=0, shuffle=False)
943+
>>> regr = BaggingRegressor(base_estimator=SVR(),
944+
... n_estimators=10, random_state=0).fit(X, y)
945+
>>> regr.predict([[0, 0, 0, 0]])
946+
array([-2.8720...])
947+
938948
References
939949
----------
940950

0 commit comments

Comments
 (0)
0