-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MRG] nosetests to pytests #310
[MRG] nosetests to pytests #310
Conversation
Hello @massich! Thanks for updating the PR.
Comment last updated on August 17, 2017 at 15:57 Hours UTC |
Codecov Report
@@ Coverage Diff @@
## master #310 +/- ##
========================================
+ Coverage 97.99% 98% +<.01%
========================================
Files 66 66
Lines 3847 3860 +13
========================================
+ Hits 3770 3783 +13
Misses 77 77
Continue to review full report at Codecov.
|
@massich thanks for this one! A little note. Instead of creating objects couldn't we use pytest fixtures? We could create a sampler object @pytest.fixture
def sampler():
return RandomOverSampler(random_state=RND_SEED) and then pass it in any test case def test_ros_fit_sample_half(sampler):
ratio = 0.5
X_resampled, y_resampled = sampler.fit_sample(X, Y)
X_gt = np.array([[0.04352327, -0.20515826],
[0.92923648, 0.76103773],
[0.20792588, 1.49407907],
[0.47104475, 0.44386323],
[0.22950086, 0.33367433],
[0.15490546, 0.3130677],
[0.09125309, -0.85409574],
[0.12372842, 0.6536186],
[0.13347175, 0.12167502],
[0.094035, -2.55298982]])
y_gt = np.array([1, 0, 1, 0, 1, 1, 1, 1, 0, 1])
assert_array_equal(X_resampled, X_gt)
assert_array_equal(y_resampled, y_gt) Of course, the same could have been applied for the datasets as well. |
@chkoar This was exactly the point :) (its just that I'm not quite done. I'm the slow kind) |
1b22868
to
33660d4
Compare
a9dd328
to
d67c301
Compare
Right now only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just have to check RENN n_jobs
assert_equal(ee.n_subsets, 10) | ||
assert_equal(ee.random_state, RND_SEED) | ||
assert ee.ratio == ratio | ||
assert not ee.replacement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert ee.replacement is False
@@ -436,22 +428,22 @@ def test_iba_sklearn_metrics(): | |||
acc = make_index_balanced_accuracy(alpha=0.5, squared=True)( | |||
accuracy_score) | |||
score = acc(y_true, y_pred) | |||
assert_equal(score, 0.54756) | |||
assert score == 0.54756 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you replace those by assert_almost_equal instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or assert_allclose because we use it before in fact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the numpy doc recommend the latests one
|
||
jss = make_index_balanced_accuracy(alpha=0.5, squared=True)( | ||
jaccard_similarity_score) | ||
score = jss(y_true, y_pred) | ||
assert_equal(score, 0.54756) | ||
assert score == 0.54756 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you replace those by assert_almost_equal instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_allclose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it be better to do:
from pytest import approx
assert score == approx(0.54756)
|
||
pre = make_index_balanced_accuracy(alpha=0.5, squared=True)( | ||
precision_score) | ||
score = pre(y_true, y_pred) | ||
assert_equal(score, 0.65025) | ||
assert score == 0.65025 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you replace those by assert_almost_equal instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_allclose
|
||
rec = make_index_balanced_accuracy(alpha=0.5, squared=True)( | ||
recall_score) | ||
score = rec(y_true, y_pred) | ||
assert_equal(score, 0.41616000000000009) | ||
assert score == 0.41616000000000009 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you replace those by assert_almost_equal instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_allclose
imblearn/tests/test_pipeline.py
Outdated
'm2__mult': 2, | ||
'last__mult': 5, | ||
}) | ||
_expected_params = {'steps': pipeline.steps, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected_params
imblearn/tests/test_pipeline.py
Outdated
@@ -641,7 +636,7 @@ def test_pipeline_memory_transformer(): | |||
cached_pipe.fit(X, y) | |||
pipe.fit(X, y) | |||
# Get the time stamp of the tranformer in the cached pipeline | |||
ts = cached_pipe.named_steps['transf'].timestamp_ | |||
_expected_ts = cached_pipe.named_steps['transf'].timestamp_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected_ts
assert_equal(renn.random_state, RND_SEED) | ||
assert renn.n_neighbors == 3 | ||
assert renn.kind_sel == 'all' | ||
assert renn.n_jobs == -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm this is strange we setup n_jobs to 1 normally. there is something fishy
imblearn/utils/estimator_checks.py
Outdated
sampler = Sampler(random_state=0) | ||
_expected_stat = Counter(y)[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected_stat
@@ -46,17 +46,16 @@ def test_check_ratio_error(): | |||
|
|||
|
|||
def test_ratio_all_over_sampling(): | |||
_expected_ratio = {1: 50, 2: 0, 3: 75} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected_ratio
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually you don't need to define it anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep it, for readability. Otherwise I would do something like:
def test_ratio_all_over_sampling():
y = np.array([1] * 50 + [2] * 100 + [3] * 25)
for each in ('all', 'auto'):
out = check_ratio(each, y, 'over-sampling')
assert out == {1: 50, 2: 0, 3: 75}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not convince since we don't do anything with check_ractio neither with the expected values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We wont agree on this one. But since its less than 80 characters. I've no more arguments, just preferences.
assert check_ratio(each, y, 'over-sampling') == {1: 50, 2: 0, 3: 75}
dbb2d1e
to
78ce012
Compare
78ce012
to
b0dd825
Compare
Reference Issue
What does this implement/fix? Explain your changes.
Any other comments?