Skip to content

implement / benchmark loguniform distribution for randomized search #9919

Closed

Description

@amueller

Most of our standard grid searches use logarithmic scales. For the randomized search we approximate that using the exponential distribution. It might be quite a bit better to use an actual log uniform distribution. It would be great if someone could benchmark that and possibly add the log uniform distribution (to the utils?).

Activity

  1. amueller commented on Oct 13, 2017

    @amueller
    MemberAuthor

    Log uniform should look like:

    def lognuniform(low=0, high=1, size=None, base=np.exp(1)):
        return np.power(base, np.random.uniform(low, high, size))

    (though it needs a slightly different API for use in RandomizedSearchCV)

  2. sauln commented on Oct 15, 2017

    @sauln

    I'd like to handle this issue!

  3. sauln commented on Oct 15, 2017

    @sauln

    I spent some time digging into this and couldn’t find the exponential distribution the issue refers to. Any direction would be appreciated. Otherwise I’ll stick with the Easy tags for now.

  4. amueller commented on Nov 7, 2017

    @amueller
    MemberAuthor

    @sauln scipy.stats.expon

  5. FarahSaeed commented on Dec 7, 2017

    @FarahSaeed
    Contributor

    @sauln I'd like to work on this if not already being worked on :)

  6. sauln commented on Dec 7, 2017

    @sauln

    @FarahSaeed If you want to, by all means.

    It would be great if you started from my branch, 50e0320. I think log uniform is implemented correctly, but I haven't fully tested it or integrated it into the documentation.

    See https://github.com/sauln/scikit-learn/blob/50e0320f211d2e70ba194f8589283b2cf7551b01/sklearn/utils/random.py#L204 for the implementation

    I started putting together some benchmarks, but was having trouble figuring out exactly what to benchmark.

  7. amueller commented on Dec 8, 2017

    @amueller
    MemberAuthor

    With benchmark I meant as parameter distribution for SVC or regularization in linear models. Sorry If I was being unclear.

  8. jscheithe commented on Apr 12, 2018

    @jscheithe

    I don't know if this is helpful or not, but I want to share the solution I found here

    import numpy as np
    import scipy as sp
    
    from sklearn.svm import SVC
    from sklearn.model_selection import RandomizedSearchCV
    
    class log_uniform():        
        def __init__(self, a=-1, b=0, base=10):
            self.loc = a
            self.scale = b - a
            self.base = base
    
        def rvs(self, size=1, random_state=None):
            uniform = sp.stats.uniform(loc=self.loc, scale=self.scale)
            return np.power(self.base, uniform.rvs(size=size, random_state=random_state))
    
    param_distributions = {
            'C' : log_uniform(-1, 4),
            'gamma' : log_uniform(-5, 1)
            }
    RandomizedSearchCV(SVC(), param_distributions)
    
  9. stsievert commented on May 30, 2018

    @stsievert
    Contributor

    @sauln could you submit a PR for your implementation? I'd like to have a user facing API for this.

  10. sauln commented on May 31, 2018

    @sauln

    Sure, I'll get it merged in tonight.

  11. sauln commented on Jun 4, 2018

    @sauln

    @stsievert, apologies, it will be a few weeks until I have the bandwidth to set up a PR. If you need it sooner, please feel free to copy the code.

  12. stsievert commented on Jun 5, 2018

    @stsievert
    Contributor

    Thanks for that. I'll set up a PR soon, and make sure to credit you in the description.

  13. janvanrijn commented on Jul 4, 2018

    @janvanrijn
    Contributor

    @amueller this would be highly relevant for our project with LMU (and currently relies on custom code in the notorious openml study 14 repo). @stsievert Is there anything I can do to facilitate this PR?

  14. stsievert commented on Jul 4, 2018

    @stsievert
    Contributor

    @janvanrijn I've gone and updated that PR, and it's very near completion. If you want something, feel free to fork my repo and put in a PR to my branch lograndom.

  15. janvanrijn commented on Oct 29, 2018

    @janvanrijn
    Contributor

    @amueller @stsievert This PR is still very relevant to our projects. Is there anything I can do to facilitate or help moving this PR forward?

  16. amueller commented on Oct 29, 2018

    @amueller
    MemberAuthor

    I would have liked to see benchmark that this actually is good if we want to recommend using that, but it looked like @jnothman didn't mind that much? Right now there's merge conflicts. If we want to merge without adding benchmarks that's the main issue. @janvanrijn if you want to provide benchmarks that this is better than expon (or tell one of our students to do that) I think that would be interesting.
    Or we can just resolve merge conflicts and I review...

  17. janvanrijn commented on Oct 29, 2018

    @janvanrijn
    Contributor

    I'm happy to add the benchmarks.

    You mean compare the added distribution with this distribution?

  18. amueller commented on Oct 29, 2018

    @amueller
    MemberAuthor

    yeah. I actually thought we had used that in the docs but it looks like we didn't because it didn't work well lol.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions