Skip to content

[MRG+1] Fix bad fp-comparisons#11591

Merged
GaelVaroquaux merged 4 commits intoscikit-learn:masterfrom
jeremiedbb:fix-floating-p-comparison
Jul 18, 2018
Merged

[MRG+1] Fix bad fp-comparisons#11591
GaelVaroquaux merged 4 commits intoscikit-learn:masterfrom
jeremiedbb:fix-floating-p-comparison

Conversation

@jeremiedbb
Copy link
Copy Markdown
Member

@jeremiedbb jeremiedbb commented Jul 17, 2018

Fixes #11551

changed exact comparison with between float values by np.isclose where needed.

  • sklearn/discriminant_analysis.py -> if self.priors_.sum() != 1
  • sklearn/utils/random.py -> if np.sum(class_prob_j) != 1.0:
  • examples/applications/wikipedia_principal_eigenvector.py
    -> np.asarray(np.where(X.sum(axis=1) == 0, 1.0 / n, 0)).ravel()
  • sklearn/metrics/base.py -> if average_weight.sum() == 0:

edit: removed 2. They were in cython functions, within nogil statement.

Copy link
Copy Markdown
Member

@qinhanmin2014 qinhanmin2014 left a comment

Choose a reason for hiding this comment

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

I'm fine with merging without a test.

@qinhanmin2014 qinhanmin2014 changed the title [MRG] Fix bad fp-comparison in discriminant_analysis [MRG+1] Fix bad fp-comparison in discriminant_analysis Jul 17, 2018
@jeremiedbb jeremiedbb changed the title [MRG+1] Fix bad fp-comparison in discriminant_analysis [WIP] Fix bad fp-comparisons Jul 18, 2018
@jeremiedbb jeremiedbb changed the title [WIP] Fix bad fp-comparisons [MRG] Fix bad fp-comparisons Jul 18, 2018

# disabling joblib as the pickling of large dicts seems much too slow
#@memory.cache
# @memory.cache
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've decided not to fix existing flake8 errors.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok sorry. What the reason behind that ?

dangle = np.asarray(np.where(X.sum(axis=1) == 0, 1.0 / n, 0)).ravel()
dangle = np.asarray(np.where(np.isclose(X.sum(axis=1), 0),
1.0 / n,
0)).ravel()
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.

don't need an extra line here?


return scores


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.

please avoid unnecessary changes.

Copy link
Copy Markdown
Member

@qinhanmin2014 qinhanmin2014 left a comment

Choose a reason for hiding this comment

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

LGTM, I'll try to mark it as 0.20.

@qinhanmin2014 qinhanmin2014 added this to the 0.20 milestone Jul 18, 2018
@qinhanmin2014 qinhanmin2014 changed the title [MRG] Fix bad fp-comparisons [MRG+1] Fix bad fp-comparisons Jul 18, 2018
Copy link
Copy Markdown
Member

@GaelVaroquaux GaelVaroquaux left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you

Merging

@GaelVaroquaux GaelVaroquaux merged commit bf11d44 into scikit-learn:master Jul 18, 2018
@jeremiedbb jeremiedbb deleted the fix-floating-p-comparison branch July 18, 2018 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad fp-comparison in the repo

3 participants