From 17a59e8b6aa056c5c27b67d07b8c8da899245e59 Mon Sep 17 00:00:00 2001 From: Nikita Singh Date: Sat, 4 Mar 2017 16:25:37 -0500 Subject: [PATCH 1/5] Separated tests for regression features in test_sample_weight_invariance --- sklearn/metrics/tests/test_common.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sklearn/metrics/tests/test_common.py b/sklearn/metrics/tests/test_common.py index a91fc57c74a77..9978b3559992d 100644 --- a/sklearn/metrics/tests/test_common.py +++ b/sklearn/metrics/tests/test_common.py @@ -1013,6 +1013,19 @@ 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,)) + y_score = 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 or + name in METRIC_UNDEFINED_BINARY): + 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) @@ -1020,6 +1033,8 @@ def test_sample_weight_invariance(n_samples=50): 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 @@ -1037,6 +1052,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 From 9f8e306e0112f56639b90622bad9ecdc541891c9 Mon Sep 17 00:00:00 2001 From: Nikita Singh Date: Sat, 4 Mar 2017 19:15:29 -0500 Subject: [PATCH 2/5] Fixed pep8 --- sklearn/metrics/tests/test_common.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sklearn/metrics/tests/test_common.py b/sklearn/metrics/tests/test_common.py index 9978b3559992d..ec95bbdf5fb2e 100644 --- a/sklearn/metrics/tests/test_common.py +++ b/sklearn/metrics/tests/test_common.py @@ -1021,11 +1021,11 @@ def test_sample_weight_invariance(n_samples=50): if name not in REGRESSION_METRICS: continue if (name in METRICS_WITHOUT_SAMPLE_WEIGHT or - name in METRIC_UNDEFINED_BINARY): - continue - metric = ALL_METRICS[name] - yield _named_check(check_sample_weight_invariance, name), name,\ - metric, y_true, y_pred + name in METRIC_UNDEFINED_BINARY): + 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) From e3a21025b6be797e282066610beb0c9296acda5a Mon Sep 17 00:00:00 2001 From: Nikita Singh Date: Sun, 5 Mar 2017 01:57:38 -0500 Subject: [PATCH 3/5] Removed unecessary check for regression --- sklearn/metrics/tests/test_common.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/sklearn/metrics/tests/test_common.py b/sklearn/metrics/tests/test_common.py index ec95bbdf5fb2e..714a3e4c52acf 100644 --- a/sklearn/metrics/tests/test_common.py +++ b/sklearn/metrics/tests/test_common.py @@ -1020,9 +1020,6 @@ def test_sample_weight_invariance(n_samples=50): for name in ALL_METRICS: if name not in REGRESSION_METRICS: continue - if (name in METRICS_WITHOUT_SAMPLE_WEIGHT or - name in METRIC_UNDEFINED_BINARY): - continue metric = ALL_METRICS[name] yield _named_check(check_sample_weight_invariance, name), name,\ metric, y_true, y_pred From 9e240fa0eb35ff53ae4377c6ef53bf61802f818f Mon Sep 17 00:00:00 2001 From: Nikita Singh Date: Sun, 5 Mar 2017 02:30:45 -0500 Subject: [PATCH 4/5] Updated regression metrics --- sklearn/metrics/tests/test_common.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sklearn/metrics/tests/test_common.py b/sklearn/metrics/tests/test_common.py index 9978b3559992d..ec95bbdf5fb2e 100644 --- a/sklearn/metrics/tests/test_common.py +++ b/sklearn/metrics/tests/test_common.py @@ -1021,11 +1021,11 @@ def test_sample_weight_invariance(n_samples=50): if name not in REGRESSION_METRICS: continue if (name in METRICS_WITHOUT_SAMPLE_WEIGHT or - name in METRIC_UNDEFINED_BINARY): - continue - metric = ALL_METRICS[name] - yield _named_check(check_sample_weight_invariance, name), name,\ - metric, y_true, y_pred + name in METRIC_UNDEFINED_BINARY): + 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) From 5e19b9a38b358d842482ab79fd17c9ad925e665b Mon Sep 17 00:00:00 2001 From: Nikita Singh Date: Sun, 5 Mar 2017 11:43:53 -0500 Subject: [PATCH 5/5] Joel's suggestions --- sklearn/metrics/tests/test_common.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sklearn/metrics/tests/test_common.py b/sklearn/metrics/tests/test_common.py index ec95bbdf5fb2e..00db32e1ef389 100644 --- a/sklearn/metrics/tests/test_common.py +++ b/sklearn/metrics/tests/test_common.py @@ -1016,12 +1016,10 @@ def test_sample_weight_invariance(n_samples=50): # regression y_true = random_state.random_sample(size=(n_samples,)) y_pred = random_state.random_sample(size=(n_samples,)) - y_score = 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 or - name in METRIC_UNDEFINED_BINARY): + if name in METRICS_WITHOUT_SAMPLE_WEIGHT: continue metric = ALL_METRICS[name] yield _named_check(check_sample_weight_invariance, name), name,\