Skip to content

Restructure percentile methods #10736

Closed
Closed

Activity

  1. eric-wieser commented on Mar 13, 2018

    @eric-wieser
    Member

    I think this already exists? Using the wikipedia example:

    >>> np.percentile(15, 20, 35, 40, 50], [5, 30, 40, 50, 100], interpolation='lower')
    array([15, 20, 20, 35, 50])
  2. added
    57 - Close?
    on Mar 13, 2018
  3. ricardoV94 commented on Mar 13, 2018

    @ricardoV94
    Author

    It does not. Look at example 2 in the wikipedia page:

    >>> np.percentile([3, 6, 7, 8, 8, 10, 13, 15, 16, 20], [25,50,75,100], interpolation='lower')
    array([ 7,  8, 13, 20])

    When it should be [7,8,15,20]

    It similarly fails in the third example

  4. seberg commented on Mar 13, 2018

    @seberg
    Member

    Nearest sounds a lot like "nearest"? Though there is always another point about how exactly the boundaries work.
    EDIT: That is, where exactly is 0 and 100 considered to be, at the datapoint or before the datapoint? (that is IIRC, anyway there are a lot of annoying complexities here)

  5. seberg commented on Mar 13, 2018

    @seberg
    Member

    don't want to read it, I think the difference might be the C parameter further down, so if someone who knows this wants to add this....

  6. seberg commented on Mar 13, 2018

    @seberg
    Member

    Frankly, I think adding the C parameter would likely really be good. But mostly better documentation would be nice, and someone who really knows this stuff is needed....

  7. ricardoV94 commented on Mar 13, 2018

    @ricardoV94
    Author

    I don't know if this has anything to do with the C-parameter, although I agree that the option of choosing it could be desirable.

    I have found another thread that incidentally brought up this issue (Dec. 2016). It seems that the algorithm I am looking for (and which wikipedia calls nearest-rank) is mentioned in this commonly cited paper by Hyndman-Fan (H&F) as being the oldest and most studied definition of percentile (it was the one I learned in Stats course). It is a discontinuous function, so I think the parameter C does not apply here (I may be wrong).

    Here is how it would look like against the other options provided by numpy that intuitively seem to compute a similar thing (i.e., 'lower', 'nearest'):

    percentiles

  8. seberg commented on Mar 13, 2018

    @seberg
    Member

    To me it looks exactly like the C parameter on first sight, the nearest curve is more stretched then the H&F curve, which is expected since numpy uses 1 and apparently H&F uses 0.

  9. seberg commented on Mar 13, 2018

    @seberg
    Member

    If you want proof. Repeat the whole thing with the same values repeated 1000 times, my guess is they will converge.
    EDIT: Or maybe not, don't have the patience or time to really think about it. But I still think it is the C parameter wikipedia mentions, so please proof me wrong :)

  10. eric-wieser commented on Mar 13, 2018

    @eric-wieser
    Member

    A graph like that would be a great addition to the percentile docs

    edit: preferably one showing the open/closedness of the discontinuities

    Note to readers: To keep this thread manageable, I've marked all discussions below about adding this graph to the docs as "resolved". The graph is now at the bottom of https://numpy.org/devdocs/reference/generated/numpy.percentile.html.

  11. ricardoV94 commented on Mar 13, 2018

    @ricardoV94
    Author
  12. ricardoV94 commented on Mar 13, 2018

    @ricardoV94
    Author

    @seberg I will be honest here, I don't know how the interpolation is being calculated based on the C-parameter. What makes me think that it is not related is that the C-parameter is only discussed in the linear interpolation section (Wikipedia), and both the Wikipedia and Hyndmand & Fan paper discuss the algorithm I requested in separate sections from the interpolation ones.

    I don't know if there is any interpolation parameters that always give the same results as the algorithm I am interested in.

    Even if there are, should this be the way used to get to it? Changing a 'strange' parameter to get the most common definition of percentile does not seem the best way to implement it imho.

  13. seberg commented on Mar 13, 2018

    @seberg
    Member

    @ricardoV94, maybe, but you can't just change the defaults, no matter how bad they are. We could expose something like method="H&K" to override both parameters at once.

    The C parameters is where you define 0% and 100% to be with respect to the datapoints (on the data point or not, etc.). As parameter C on wikipedia, it may well be only for interpolation, but the same issue causes the difference here I am sure. C is dubious of course, a proper name might be something like range='min-max' or range='extrapolated' or probably something completely different. As I said, redo the plots with many many datapoints (possibly with tiny noise), and I think you will see them converge, since the range definition becomes less obvious.

  14. ricardoV94 commented on Mar 13, 2018

    @ricardoV94
    Author

    @seberg I am fine with method="H&K" or maybe method="classic". Interpolation="none" could also make sense.

  15. eric-wieser commented on Mar 13, 2018

    @eric-wieser
  16. 69 remaining items

  17. added 2 commits that reference this issue on Sep 9, 2021
  18. abel-bzz commented on Sep 16, 2021

    @abel-bzz
    Contributor

    The implementation of "the 9" is complete, I was inspired by your paper @robjhyndman as well as your library @ricardoV94 among other sources.
    Would you give your OK for this feature ?
    I already added a reference to the paper in the documentation, what else can I do to give the due credit ?

  19. robjhyndman commented on Sep 16, 2021

    @robjhyndman

    Not sure what you want my OK for. But happy to see this implemented in python. A reference to the 1996 paper is sufficient.

  20. ricardoV94 commented on Sep 17, 2021

    @ricardoV94
    Author

    The implementation of "the 9" is complete, I was inspired by your paper @robjhyndman as well as your library @ricardoV94 among other sources.
    Would you give your OK for this feature ?
    I already added a reference to the paper in the documentation, what else can I do to give the due credit ?

    No need to mention my library :)

  21. added
    62 - Python API
    on Sep 21, 2021
  22. added 2 commits that reference this issue on Oct 6, 2021
  23. added a commit that references this issue on Oct 21, 2021
  24. added 2 commits that reference this issue on Nov 1, 2021
  25. jiglesiasc commented on Nov 8, 2021

    @jiglesiasc

    I'm 100% an user and not a coder so I just wanted to add my thoughts after reading this thread and the other one related:

    • It's not really that important if you stick to H&F paper or Wikipedia both accomplish more or less the same thing, as long as you clearly state in the documentation: "this percentile method is based on XXXXX". The current documentation for numpy.percentile the definition of the linear interpolation is quite vague, this is why I'm here.
    • It is fundamental that numpy.percentile include more methods for linear interpolation, specially definition 6 from H&F which is widely used on a lot of software packages. This is necessary because the users we have to compare a lot our calculations with the calculation from a particular study. As for today numpy.percentile works only as a tool for own study but not to compare with others, which makes it less useful.
    • The default method is not really that relevant IMO. All of the method tend to get closer when N is large. As seen in H&F some methods have more desired properties than others but all the linear methods accomplish 5 out of 6 properties except definition 5 which accomplish all 6 properties. But I get what you said that you wanted to follow R. But why follow R and not Matlab? or not Excel? any particular reason just out of curiosity?
  26. abel-bzz commented on Nov 8, 2021

    @abel-bzz
    Contributor

    Hello @jiglesiasc, the 9 methods have been merged on main branch with #19857.
    If everything goes right this feature should be available with numpy's next release I think.

    I'm not sure if the issue should stay open though.

  27. seberg commented on Nov 8, 2021

    @seberg
    Member

    Yeah, lets close it. The main thing is that I want to quickly follow-up to rename interpolation to method. If anyone here has further hints/suggestions, please also check the new docs: https://numpy.org/devdocs/reference/generated/numpy.quantile.html changing names, etc. should happen within the next few weeks (or we miss the next release).

    I think the current docs are good, but a snippet of text to guide users towards (safe) choices may be nice.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bug01 - Enhancement62 - Python APIPriority: hightriage review

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions