Skip to content

Commit

Permalink
TST set random state in scoring tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glemaitre committed Aug 23, 2017
1 parent 108105d commit a2de53a
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions imblearn/metrics/tests/test_score_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,86 +32,102 @@ def test_imblearn_classification_scorers():

# sensitivity scorer
scorer = make_scorer(sensitivity_score, pos_label=None, average='macro')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

scorer = make_scorer(sensitivity_score, pos_label=None, average='weighted')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

scorer = make_scorer(sensitivity_score, pos_label=None, average='micro')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

scorer = make_scorer(sensitivity_score, pos_label=1)
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

# specificity scorer
scorer = make_scorer(specificity_score, pos_label=None, average='macro')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

scorer = make_scorer(specificity_score, pos_label=None, average='weighted')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

scorer = make_scorer(specificity_score, pos_label=None, average='micro')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

scorer = make_scorer(specificity_score, pos_label=1)
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.95, rtol=R_TOL)

# geometric_mean scorer
scorer = make_scorer(geometric_mean_score, pos_label=None, average='macro')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

scorer = make_scorer(
geometric_mean_score, pos_label=None, average='weighted')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

scorer = make_scorer(geometric_mean_score, pos_label=None, average='micro')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

scorer = make_scorer(geometric_mean_score, pos_label=1)
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

# make a iba metric before a scorer
geo_mean_iba = make_index_balanced_accuracy()(geometric_mean_score)
scorer = make_scorer(geo_mean_iba, pos_label=None, average='macro')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.85, rtol=R_TOL)

scorer = make_scorer(geo_mean_iba, pos_label=None, average='weighted')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.85, rtol=R_TOL)

scorer = make_scorer(geo_mean_iba, pos_label=None, average='micro')
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.85, rtol=R_TOL)

scorer = make_scorer(geo_mean_iba, pos_label=1)
grid = GridSearchCV(LinearSVC(), param_grid={'C': [1, 10]}, scoring=scorer)
grid = GridSearchCV(LinearSVC(random_state=0), param_grid={'C': [1, 10]},
scoring=scorer)
grid.fit(X_train, y_train).predict(X_test)
assert_allclose(grid.best_score_, 0.84, rtol=R_TOL)

0 comments on commit a2de53a

Please sign in to comment.