|
12 | 12 | from sklearn.ensemble import BaggingClassifier |
13 | 13 | from sklearn.ensemble._base import _set_random_states |
14 | 14 | from sklearn.linear_model import Perceptron |
| 15 | +from sklearn.linear_model import Ridge, LogisticRegression |
15 | 16 | from collections import OrderedDict |
16 | 17 | from sklearn.discriminant_analysis import LinearDiscriminantAnalysis |
17 | 18 | from sklearn.pipeline import Pipeline |
18 | 19 | from sklearn.feature_selection import SelectFromModel |
| 20 | +from sklearn import ensemble |
19 | 21 |
|
20 | 22 |
|
21 | 23 | def test_base(): |
@@ -117,3 +119,25 @@ def test_validate_estimator_value_error(): |
117 | 119 | err_msg = "Both `estimator` and `base_estimator` were set. Only set `estimator`." |
118 | 120 | with pytest.raises(ValueError, match=err_msg): |
119 | 121 | model.fit(X, y) |
| 122 | + |
| 123 | + |
| 124 | +# TODO(1.4): remove |
| 125 | +@pytest.mark.parametrize( |
| 126 | + "model", |
| 127 | + [ |
| 128 | + ensemble.GradientBoostingClassifier(), |
| 129 | + ensemble.GradientBoostingRegressor(), |
| 130 | + ensemble.HistGradientBoostingClassifier(), |
| 131 | + ensemble.HistGradientBoostingRegressor(), |
| 132 | + ensemble.VotingClassifier( |
| 133 | + [("a", LogisticRegression()), ("b", LogisticRegression())] |
| 134 | + ), |
| 135 | + ensemble.VotingRegressor([("a", Ridge()), ("b", Ridge())]), |
| 136 | + ], |
| 137 | +) |
| 138 | +def test_estimator_attribute_error(model): |
| 139 | + X = [[1], [2]] |
| 140 | + y = [0, 1] |
| 141 | + model.fit(X, y) |
| 142 | + |
| 143 | + assert not hasattr(model, "estimator_") |
0 commit comments