Skip to content

Commit

Permalink
[MRG] Separated regression metrics from other metrics in test_sample_…
Browse files Browse the repository at this point in the history
…weight_invariance in metrics/tests/test_common.py (scikit-learn#8537)

* Separated tests for regression features in test_sample_weight_invariance

* Fixed pep8

* Removed unecessary check for regression

* Updated regression metrics

* Joel's suggestions
  • Loading branch information
nikitasingh981 authored and GaelVaroquaux committed Mar 5, 2017
1 parent 6852a03 commit a36c852
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sklearn/metrics/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,13 +1013,26 @@ def check_sample_weight_invariance(name, metric, y1, y2):

def test_sample_weight_invariance(n_samples=50):
random_state = check_random_state(0)
# regression
y_true = random_state.random_sample(size=(n_samples,))
y_pred = random_state.random_sample(size=(n_samples,))
for name in ALL_METRICS:
if name not in REGRESSION_METRICS:
continue
if name in METRICS_WITHOUT_SAMPLE_WEIGHT:
continue
metric = ALL_METRICS[name]
yield _named_check(check_sample_weight_invariance, name), name,\
metric, y_true, y_pred

# binary
random_state = check_random_state(0)
y_true = random_state.randint(0, 2, size=(n_samples, ))
y_pred = random_state.randint(0, 2, size=(n_samples, ))
y_score = random_state.random_sample(size=(n_samples,))
for name in ALL_METRICS:
if name in REGRESSION_METRICS:
continue
if (name in METRICS_WITHOUT_SAMPLE_WEIGHT or
name in METRIC_UNDEFINED_BINARY):
continue
Expand All @@ -1037,6 +1050,8 @@ def test_sample_weight_invariance(n_samples=50):
y_pred = random_state.randint(0, 5, size=(n_samples, ))
y_score = random_state.random_sample(size=(n_samples, 5))
for name in ALL_METRICS:
if name in REGRESSION_METRICS:
continue
if (name in METRICS_WITHOUT_SAMPLE_WEIGHT or
name in METRIC_UNDEFINED_BINARY_MULTICLASS):
continue
Expand Down

0 comments on commit a36c852

Please sign in to comment.