Skip to content
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

【Python】Floating-point precision of the split node #5298

Closed
XTmingyue opened this issue Feb 10, 2020 · 4 comments
Closed

【Python】Floating-point precision of the split node #5298

XTmingyue opened this issue Feb 10, 2020 · 4 comments

Comments

@XTmingyue
Copy link

I have encountered an unusual situation:

A model shows the split point for a particular node as follows:

4:[f21<166.666702] yes=9,no=10,missing=9

If I feed in an observation where f21 = 166.6667 the python model incorrectly sends this to the yes node. I've limited the number of floating-point numbers in Python to four decimal places.

@trivialfis
Copy link
Member

How do you limit floating point precision in Python?

@Denisevi4
Copy link

166.6667 < 166.666702

Should be a yes node. Or am I missing something?

@trivialfis
Copy link
Member

trivialfis commented Feb 21, 2020

Floating point printing is a very tricky thing, it has round off:

In [1]: print('{:.17f}'.format(166.666702))                                                                                                                                                                 
166.66670199999998658

And the round off mode is dependent on implementation.

@trivialfis
Copy link
Member

trivialfis commented Mar 18, 2020

Also 1.0.2 is now out. Feel free to try the experimental JSON format.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants