@@ -175,6 +175,7 @@ def test_kneighbors_classifier(n_samples=40,
175
175
rng = np .random .RandomState (random_state )
176
176
X = 2 * rng .rand (n_samples , n_features ) - 1
177
177
y = ((X ** 2 ).sum (axis = 1 ) < .5 ).astype (np .int )
178
+ y_str = y .astype (str )
178
179
179
180
weight_func = _weight_func
180
181
@@ -187,6 +188,10 @@ def test_kneighbors_classifier(n_samples=40,
187
188
epsilon = 1e-5 * (2 * rng .rand (1 , n_features ) - 1 )
188
189
y_pred = knn .predict (X [:n_test_pts ] + epsilon )
189
190
assert_array_equal (y_pred , y [:n_test_pts ])
191
+ # Test prediction with y_str
192
+ knn .fit (X , y_str )
193
+ y_pred = knn .predict (X [:n_test_pts ] + epsilon )
194
+ assert_array_equal (y_pred , y_str [:n_test_pts ])
190
195
191
196
192
197
def test_kneighbors_classifier_predict_proba ():
@@ -219,6 +224,7 @@ def test_radius_neighbors_classifier(n_samples=40,
219
224
rng = np .random .RandomState (random_state )
220
225
X = 2 * rng .rand (n_samples , n_features ) - 1
221
226
y = ((X ** 2 ).sum (axis = 1 ) < .5 ).astype (np .int )
227
+ y_str = y .astype (str )
222
228
223
229
weight_func = _weight_func
224
230
@@ -231,6 +237,9 @@ def test_radius_neighbors_classifier(n_samples=40,
231
237
epsilon = 1e-5 * (2 * rng .rand (1 , n_features ) - 1 )
232
238
y_pred = neigh .predict (X [:n_test_pts ] + epsilon )
233
239
assert_array_equal (y_pred , y [:n_test_pts ])
240
+ neigh .fit (X , y_str )
241
+ y_pred = neigh .predict (X [:n_test_pts ] + epsilon )
242
+ assert_array_equal (y_pred , y_str [:n_test_pts ])
234
243
235
244
236
245
def test_radius_neighbors_classifier_when_no_neighbors ():
0 commit comments