@@ -54,15 +54,14 @@ def test_iht_bad_ratio():
54
54
ratio = ratio )
55
55
56
56
57
- # def test_iht_estimator_no_proba():
58
- # """Test either if an error is raised when the estimator does not have
59
- # predict_proba function"""
57
+ def test_iht_wrong_estimator ():
58
+ """Test either if an error is raised when the estimator is unknown"""
60
59
61
- # # Resample the data
62
- # ratio = 0.5
63
- # est = 'linear-svm '
64
- # assert_raises(ValueError , InstanceHardnessThreshold, est, ratio=ratio ,
65
- # random_state=RND_SEED)
60
+ # Resample the data
61
+ ratio = 0.5
62
+ est = 'rnd '
63
+ assert_raises (NotImplementedError , InstanceHardnessThreshold , est ,
64
+ ratio = ratio , random_state = RND_SEED )
66
65
67
66
def test_iht_init ():
68
67
"""Test the initialisation of the object"""
@@ -174,3 +173,94 @@ def test_iht_fit_sample_half():
174
173
y_gt = np .load (os .path .join (currdir , 'data' , 'iht_y_05.npy' ))
175
174
assert_array_equal (X_resampled , X_gt )
176
175
assert_array_equal (y_resampled , y_gt )
176
+
177
+
178
+ def test_iht_fit_sample_knn ():
179
+ """Test the fit sample routine with knn"""
180
+
181
+ # Resample the data
182
+ est = 'knn'
183
+ iht = InstanceHardnessThreshold (est , random_state = RND_SEED )
184
+ X_resampled , y_resampled = iht .fit_sample (X , Y )
185
+
186
+ currdir = os .path .dirname (os .path .abspath (__file__ ))
187
+ X_gt = np .load (os .path .join (currdir , 'data' , 'iht_x_knn.npy' ))
188
+ y_gt = np .load (os .path .join (currdir , 'data' , 'iht_y_knn.npy' ))
189
+ assert_array_equal (X_resampled , X_gt )
190
+ assert_array_equal (y_resampled , y_gt )
191
+
192
+
193
+ def test_iht_fit_sample_decision_tree ():
194
+ """Test the fit sample routine with decision-tree"""
195
+
196
+ # Resample the data
197
+ est = 'decision-tree'
198
+ iht = InstanceHardnessThreshold (est , random_state = RND_SEED )
199
+ X_resampled , y_resampled = iht .fit_sample (X , Y )
200
+
201
+ currdir = os .path .dirname (os .path .abspath (__file__ ))
202
+ X_gt = np .load (os .path .join (currdir , 'data' , 'iht_x_dt.npy' ))
203
+ y_gt = np .load (os .path .join (currdir , 'data' , 'iht_y_dt.npy' ))
204
+ assert_array_equal (X_resampled , X_gt )
205
+ assert_array_equal (y_resampled , y_gt )
206
+
207
+
208
+ def test_iht_fit_sample_random_forest ():
209
+ """Test the fit sample routine with random forest"""
210
+
211
+ # Resample the data
212
+ est = 'random-forest'
213
+ iht = InstanceHardnessThreshold (est , random_state = RND_SEED )
214
+ X_resampled , y_resampled = iht .fit_sample (X , Y )
215
+
216
+ currdir = os .path .dirname (os .path .abspath (__file__ ))
217
+ X_gt = np .load (os .path .join (currdir , 'data' , 'iht_x_rf.npy' ))
218
+ y_gt = np .load (os .path .join (currdir , 'data' , 'iht_y_rf.npy' ))
219
+ assert_array_equal (X_resampled , X_gt )
220
+ assert_array_equal (y_resampled , y_gt )
221
+
222
+
223
+ def test_iht_fit_sample_adaboost ():
224
+ """Test the fit sample routine with adaboost"""
225
+
226
+ # Resample the data
227
+ est = 'adaboost'
228
+ iht = InstanceHardnessThreshold (est , random_state = RND_SEED )
229
+ X_resampled , y_resampled = iht .fit_sample (X , Y )
230
+
231
+ currdir = os .path .dirname (os .path .abspath (__file__ ))
232
+ X_gt = np .load (os .path .join (currdir , 'data' , 'iht_x_adb.npy' ))
233
+ y_gt = np .load (os .path .join (currdir , 'data' , 'iht_y_adb.npy' ))
234
+ assert_array_equal (X_resampled , X_gt )
235
+ assert_array_equal (y_resampled , y_gt )
236
+
237
+
238
+
239
+ def test_iht_fit_sample_gradient_boosting ():
240
+ """Test the fit sample routine with gradient boosting"""
241
+
242
+ # Resample the data
243
+ est = 'gradient-boosting'
244
+ iht = InstanceHardnessThreshold (est , random_state = RND_SEED )
245
+ X_resampled , y_resampled = iht .fit_sample (X , Y )
246
+
247
+ currdir = os .path .dirname (os .path .abspath (__file__ ))
248
+ X_gt = np .load (os .path .join (currdir , 'data' , 'iht_x_gb.npy' ))
249
+ y_gt = np .load (os .path .join (currdir , 'data' , 'iht_y_gb.npy' ))
250
+ assert_array_equal (X_resampled , X_gt )
251
+ assert_array_equal (y_resampled , y_gt )
252
+
253
+
254
+ def test_iht_fit_sample_linear_svm ():
255
+ """Test the fit sample routine with linear SVM"""
256
+
257
+ # Resample the data
258
+ est = 'linear-svm'
259
+ iht = InstanceHardnessThreshold (est , random_state = RND_SEED )
260
+ X_resampled , y_resampled = iht .fit_sample (X , Y )
261
+
262
+ currdir = os .path .dirname (os .path .abspath (__file__ ))
263
+ X_gt = np .load (os .path .join (currdir , 'data' , 'iht_x_svm.npy' ))
264
+ y_gt = np .load (os .path .join (currdir , 'data' , 'iht_y_svm.npy' ))
265
+ assert_array_equal (X_resampled , X_gt )
266
+ assert_array_equal (y_resampled , y_gt )
0 commit comments