Skip to content

[MRG] sklearn.metrics.normalized_mutual_info_score for continuous data does not return a warning #17892 - #17911

Merged
jnothman merged 8 commits into
scikit-learn:masterfrom
dachosen1:normalized_mutual_info_score
Jul 30, 2020
Merged

jnothman merged 8 commits into
scikit-learn:masterfrom
dachosen1:normalized_mutual_info_score

Conversation

@dachosen1

@dachosen1 dachosen1 commented Jul 12, 2020 •

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #17892

What does this implement/fix? Explain your changes.

Fixes an an error where normalized_mutual_info_score for continuous data does not return a warning for continous values

Any other comments?

[Issue #17892s(#17892)

What does this implement/fix? Explain your changes.
normalized_mutual_info_score for continuous data does not return a warning
@dachosen1 dachosen1 changed the title Reference Issues/PRs [WIP] Reference Issues/PRs Jul 12, 2020
@dachosen1 dachosen1 changed the title [WIP] Reference Issues/PRs [WIP] Reference Issues/PRs #17892 warning for normalized_mutual_info_score Jul 12, 2020
noise = np.random.rand(500)
wavelength = np.linspace(0.01, 1, 500) * 1e-6

with pytest(UserWarning):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
with pytest(UserWarning):
with pytest.warns(UserWarning):

@dachosen1 dachosen1 Jul 13, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jnothman I made the change. Let me know if I need to change anything else

@dachosen1 dachosen1 changed the title [WIP] Reference Issues/PRs #17892 warning for normalized_mutual_info_score [MRG] Reference Issues/PRs #17892 warning for normalized_mutual_info_score Jul 13, 2020
@dachosen1
dachosen1 requested a review from jnothman July 16, 2020 04:35
@dachosen1

dachosen1 commented Jul 21, 2020 •

Copy link
Copy Markdown
Contributor Author

@jnothman do you have any further comments?

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The title does not need to reference the PR number, it should only describe what the PR is doing.

Thank you for the PR @dachosen1 !

Comment thread sklearn/metrics/cluster/_supervised.py Outdated
Comment on lines +61 to +63
warnings.warn(UserWarning('Expects discrete values received {} '
'for label, and {} for target'
.format(type_label, type_label)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can use f-strings here:

Suggested change
warnings.warn(UserWarning('Expects discrete values received {} '
'for label, and {} for target'
.format(type_label, type_label)))
warnings.warn(f'Expects discrete values received {type_label} '
f'for label, and {type_label} for target',
UserWarning)

Comment thread sklearn/metrics/cluster/_supervised.py Resolved
@dachosen1 dachosen1 changed the title [MRG] Reference Issues/PRs #17892 warning for normalized_mutual_info_score [MRG] sklearn.metrics.normalized_mutual_info_score for continuous data does not return a warning #17892 Jul 23, 2020
@dachosen1

dachosen1 commented Jul 23, 2020 •

Copy link
Copy Markdown
Contributor Author

The title does not need to reference the PR number, it should only describe what the PR is doing.

Noted. Thanks for the heads up.

@thomasjpfan I implemented the suggested changes. Let me know what you think.

@dachosen1
dachosen1 requested a review from thomasjpfan July 24, 2020 17:52

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment on lines +57 to +58
type_label = type_of_target(labels_true)
type_pred = type_of_target(labels_pred)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A random thought (does not block this PR): We sure call np.unique a bunch. (type_of_target calls np.unique internally).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A random thought (does not block this PR): We sure call np.unique a bunch. (type_of_target calls np.unique internally).

Yes, this is a problem of not using objects... ideally, instead of unique_labels and type_of_target we should have a Target class that reuses partial results such as unique, to improve efficiency.

@dachosen1

Copy link
Copy Markdown
Contributor Author

@jnothman do you have any other comments?

@jnothman jnothman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Otherwise LGTM

Comment thread sklearn/metrics/cluster/_supervised.py Resolved
@jnothman
jnothman merged commit e2c80b8 into scikit-learn:master Jul 30, 2020
@jnothman

Copy link
Copy Markdown
Member

Thanks @dachosen1

@dachosen1

dachosen1 commented Jul 30, 2020 •

Copy link
Copy Markdown
Contributor Author

@jnothman this is exciting. Finally completed my first open-source contribution.!!!

@jnothman

Copy link
Copy Markdown
Member

Congrats, @dachosen1!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

using sklearn.metrics.normalized_mutual_info_score for continuous data does not return a warning

3 participants