@@ -80,60 +80,131 @@ def test_classification_toy(loss):
80
80
@pytest .mark .parametrize (
81
81
"params, err_type, err_msg" ,
82
82
[
83
- ({"n_estimators" : 0 }, ValueError , "n_estimators must be greater than 0" ),
84
- ({"n_estimators" : - 1 }, ValueError , "n_estimators must be greater than 0" ),
85
- ({"learning_rate" : 0 }, ValueError , "learning_rate must be greater than 0" ),
86
- ({"learning_rate" : - 1.0 }, ValueError , "learning_rate must be greater than 0" ),
83
+ ({"learning_rate" : 0 }, ValueError , "learning_rate == 0, must be > 0.0" ),
84
+ (
85
+ {"learning_rate" : "foo" },
86
+ TypeError ,
87
+ "learning_rate must be an instance of <class 'numbers.Real'>" ,
88
+ ),
89
+ ({"n_estimators" : 0 }, ValueError , "n_estimators == 0, must be >= 1" ),
90
+ (
91
+ {"n_estimators" : 1.5 },
92
+ TypeError ,
93
+ "n_estimators must be an instance of <class 'numbers.Integral'>," ,
94
+ ),
87
95
({"loss" : "foobar" }, ValueError , "Loss 'foobar' not supported" ),
96
+ ({"subsample" : 0.0 }, ValueError , "subsample == 0.0, must be > 0.0" ),
97
+ ({"subsample" : 1.1 }, ValueError , "subsample == 1.1, must be <= 1.0" ),
88
98
(
89
- {"min_samples_split" : 0.0 },
90
- ValueError ,
91
- "min_samples_split == 0.0, must be > 0.0" ,
99
+ {"subsample" : "foo" },
100
+ TypeError ,
101
+ "subsample must be an instance of <class 'numbers.Real'>" ,
102
+ ),
103
+ ({"init" : {}}, ValueError , "The init parameter must be an estimator or 'zero'" ),
104
+ ({"max_features" : 0 }, ValueError , "max_features == 0, must be >= 1" ),
105
+ ({"max_features" : 0.0 }, ValueError , "max_features == 0.0, must be > 0.0" ),
106
+ ({"max_features" : 1.1 }, ValueError , "max_features == 1.1, must be <= 1.0" ),
107
+ ({"max_features" : "foobar" }, ValueError , "Invalid value for max_features." ),
108
+ ({"verbose" : - 1 }, ValueError , "verbose == -1, must be >= 0" ),
109
+ (
110
+ {"verbose" : "foo" },
111
+ TypeError ,
112
+ "verbose must be an instance of" ,
92
113
),
114
+ ({"warm_start" : "foo" }, TypeError , "warm_start must be an instance of" ),
93
115
(
94
- {"min_samples_split " : - 1 .0 },
116
+ {"validation_fraction " : 0 .0 },
95
117
ValueError ,
96
- "min_samples_split == -1 .0, must be > 0.0" ,
118
+ "validation_fraction == 0 .0, must be > 0.0" ,
97
119
),
98
120
(
99
- {"min_samples_split " : 1.1 },
121
+ {"validation_fraction " : 1.0 },
100
122
ValueError ,
101
- "min_samples_split == 1.1, must be <= 1.0." ,
123
+ "validation_fraction == 1.0, must be < 1.0" ,
124
+ ),
125
+ (
126
+ {"validation_fraction" : "foo" },
127
+ TypeError ,
128
+ "validation_fraction must be an instance of <class 'numbers.Real'>" ,
129
+ ),
130
+ ({"n_iter_no_change" : 0 }, ValueError , "n_iter_no_change == 0, must be >= 1" ),
131
+ (
132
+ {"n_iter_no_change" : 1.5 },
133
+ TypeError ,
134
+ "n_iter_no_change must be an instance of <class 'numbers.Integral'>," ,
135
+ ),
136
+ ({"tol" : 0.0 }, ValueError , "tol == 0.0, must be > 0.0" ),
137
+ (
138
+ {"tol" : "foo" },
139
+ TypeError ,
140
+ "tol must be an instance of <class 'numbers.Real'>," ,
102
141
),
142
+ # The following parameters are checked in BaseDecisionTree
103
143
({"min_samples_leaf" : 0 }, ValueError , "min_samples_leaf == 0, must be >= 1" ),
144
+ ({"min_samples_leaf" : 0.0 }, ValueError , "min_samples_leaf == 0.0, must be > 0" ),
145
+ (
146
+ {"min_samples_leaf" : "foo" },
147
+ TypeError ,
148
+ "min_samples_leaf must be an instance of <class 'numbers.Real'>" ,
149
+ ),
150
+ ({"min_samples_split" : 1 }, ValueError , "min_samples_split == 1, must be >= 2" ),
104
151
(
105
- {"min_samples_leaf " : - 1 .0 },
152
+ {"min_samples_split " : 0 .0 },
106
153
ValueError ,
107
- "min_samples_leaf == -1 .0, must be > 0.0. " ,
154
+ "min_samples_split == 0 .0, must be > 0.0" ,
108
155
),
109
156
(
110
- {"min_weight_fraction_leaf " : - 1.0 },
157
+ {"min_samples_split " : 1.1 },
111
158
ValueError ,
112
- "min_weight_fraction_leaf == -1.0 , must be >= 0" ,
159
+ "min_samples_split == 1.1 , must be <= 1. 0" ,
113
160
),
114
161
(
115
- {"min_weight_fraction_leaf" : 0.6 },
162
+ {"min_samples_split" : "foo" },
163
+ TypeError ,
164
+ "min_samples_split must be an instance of <class 'numbers.Real'>" ,
165
+ ),
166
+ (
167
+ {"min_weight_fraction_leaf" : - 1 },
116
168
ValueError ,
117
- "min_weight_fraction_leaf == 0.6 , must be < = 0.5. " ,
169
+ "min_weight_fraction_leaf == -1 , must be > = 0.0 " ,
118
170
),
119
- ({"subsample" : 0.0 }, ValueError , r"subsample must be in \(0,1\]" ),
120
- ({"subsample" : 1.1 }, ValueError , r"subsample must be in \(0,1\]" ),
121
- ({"subsample" : - 0.1 }, ValueError , r"subsample must be in \(0,1\]" ),
122
- ({"max_depth" : - 0.1 }, TypeError , "max_depth must be an instance of" ),
123
- ({"max_depth" : 0 }, ValueError , "max_depth == 0, must be >= 1." ),
124
- ({"init" : {}}, ValueError , "The init parameter must be an estimator or 'zero'" ),
125
- ({"max_features" : "invalid" }, ValueError , "Invalid value for max_features:" ),
126
- ({"max_features" : 0 }, ValueError , "max_features == 0, must be >= 1" ),
127
- ({"max_features" : 100 }, ValueError , "max_features == 100, must be <=" ),
128
171
(
129
- {"max_features " : - 0.1 },
172
+ {"min_weight_fraction_leaf " : 0.6 },
130
173
ValueError ,
131
- r"max_features must be in \(0, n_features\] " ,
174
+ "min_weight_fraction_leaf == 0.6, must be <= 0.5 " ,
132
175
),
133
176
(
134
- {"n_iter_no_change" : "invalid" },
177
+ {"min_weight_fraction_leaf" : "foo" },
178
+ TypeError ,
179
+ "min_weight_fraction_leaf must be an instance of <class 'numbers.Real'>" ,
180
+ ),
181
+ ({"max_leaf_nodes" : 0 }, ValueError , "max_leaf_nodes == 0, must be >= 2" ),
182
+ (
183
+ {"max_leaf_nodes" : 1.5 },
184
+ TypeError ,
185
+ "max_leaf_nodes must be an instance of <class 'numbers.Integral'>" ,
186
+ ),
187
+ ({"max_depth" : - 1 }, ValueError , "max_depth == -1, must be >= 1" ),
188
+ (
189
+ {"max_depth" : 1.1 },
190
+ TypeError ,
191
+ "max_depth must be an instance of <class 'numbers.Integral'>" ,
192
+ ),
193
+ (
194
+ {"min_impurity_decrease" : - 1 },
135
195
ValueError ,
136
- "n_iter_no_change should either be" ,
196
+ "min_impurity_decrease == -1, must be >= 0.0" ,
197
+ ),
198
+ (
199
+ {"min_impurity_decrease" : "foo" },
200
+ TypeError ,
201
+ "min_impurity_decrease must be an instance of <class 'numbers.Real'>" ,
202
+ ),
203
+ ({"ccp_alpha" : - 1.0 }, ValueError , "ccp_alpha == -1.0, must be >= 0.0" ),
204
+ (
205
+ {"ccp_alpha" : "foo" },
206
+ TypeError ,
207
+ "ccp_alpha must be an instance of <class 'numbers.Real'>" ,
137
208
),
138
209
({"criterion" : "mae" }, ValueError , "criterion='mae' is not supported." ),
139
210
],
@@ -158,8 +229,10 @@ def test_gbdt_parameter_checks(GradientBoosting, X, y, params, err_type, err_msg
158
229
@pytest .mark .parametrize (
159
230
"params, err_msg" ,
160
231
[
161
- ({"loss" : "huber" , "alpha" : 1.2 }, r"alpha must be in \(0.0, 1.0\)" ),
162
- ({"loss" : "quantile" , "alpha" : 1.2 }, r"alpha must be in \(0.0, 1.0\)" ),
232
+ ({"loss" : "huber" , "alpha" : 0.0 }, "alpha == 0.0, must be > 0.0" ),
233
+ ({"loss" : "quantile" , "alpha" : 0.0 }, "alpha == 0.0, must be > 0.0" ),
234
+ ({"loss" : "huber" , "alpha" : 1.2 }, "alpha == 1.2, must be < 1.0" ),
235
+ ({"loss" : "quantile" , "alpha" : 1.2 }, "alpha == 1.2, must be < 1.0" ),
163
236
],
164
237
)
165
238
def test_gbdt_loss_alpha_error (params , err_msg ):
@@ -1389,7 +1462,7 @@ def test_early_stopping_n_classes():
1389
1462
X = [[1 ]] * 10
1390
1463
y = [0 , 0 ] + [1 ] * 8 # only 2 negative class over 10 samples
1391
1464
gb = GradientBoostingClassifier (
1392
- n_iter_no_change = 5 , random_state = 0 , validation_fraction = 8
1465
+ n_iter_no_change = 5 , random_state = 0 , validation_fraction = 0. 8
1393
1466
)
1394
1467
with pytest .raises (
1395
1468
ValueError , match = "The training data after the early stopping split"
@@ -1398,7 +1471,7 @@ def test_early_stopping_n_classes():
1398
1471
1399
1472
# No error if we let training data be big enough
1400
1473
gb = GradientBoostingClassifier (
1401
- n_iter_no_change = 5 , random_state = 0 , validation_fraction = 4
1474
+ n_iter_no_change = 5 , random_state = 0 , validation_fraction = 0. 4
1402
1475
)
1403
1476
1404
1477
0 commit comments