Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG] Fixing wrapping in named_test.test_common #8558

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

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions sklearn/metrics/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,11 @@

# No Sample weight support
METRICS_WITHOUT_SAMPLE_WEIGHT = [
"confusion_matrix", # Left this one here because the tests in this file do
# not work for confusion_matrix, as its output is a
# matrix instead of a number. Testing of
# confusion_matrix with sample_weight is in
# test_classification.py
"confusion_matrix", # Left this one here because the tests in this file do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now but from next time kindly avoid unrelated changes :)

# not work for confusion_matrix, as its output is a
# matrix instead of a number. Testing of
# confusion_matrix with sample_weight is in
# test_classification.py
"median_absolute_error",
]

Expand Down Expand Up @@ -619,9 +619,9 @@ def test_invariance_string_vs_numbers_labels():


def test_inf_nan_input():
invalids =[([0, 1], [np.inf, np.inf]),
([0, 1], [np.nan, np.nan]),
([0, 1], [np.nan, np.inf])]
invalids = [([0, 1], [np.inf, np.inf]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

([0, 1], [np.nan, np.nan]),
([0, 1], [np.nan, np.inf])]

METRICS = dict()
METRICS.update(THRESHOLDED_METRICS)
Expand Down Expand Up @@ -1011,7 +1011,8 @@ def check_sample_weight_invariance(name, metric, y1, y2):
sample_weight=np.hstack([sample_weight, sample_weight]))


def test_sample_weight_invariance(n_samples=50):
def generate_sample_weight_invariance(n_samples=50):
# create generative function to iterate through each relevant metric
random_state = check_random_state(0)
# regression
y_true = random_state.random_sample(size=(n_samples,))
Expand Down Expand Up @@ -1088,6 +1089,12 @@ def test_sample_weight_invariance(n_samples=50):
metric, y_true, y_pred)


def test_sample_weight_invariance(n_samples=50):
# iterate through each metric testing each case
for metrics in generate_sample_weight_invariance(n_samples):
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the original issue as I commented there and I don't think you need this since nose supports yield in test functions ...



@ignore_warnings
def test_no_averaging_labels():
# test labels argument when not using averaging
Expand Down