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] Accept numpy generators as random_state #9743

Merged
merged 3 commits into from
Nov 1, 2023

Conversation

david-cortes
Copy link
Contributor

This PR modifies the scikit-learn interface to accept numpy generators as possible inputs for random_state. Generators are now the recommended mechanism for drawing random numbers in numpy, while the previous RandomState is deprecated. Lots of other software like SciPy have moved towards the new Generator class and allow passing a random_state as either int/RandomState/Generator (example).

Copy link
Member

@trivialfis trivialfis left a comment

Choose a reason for hiding this comment

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

Thank you for the work on rng!

@trivialfis
Copy link
Member

Hi, could you please help take a look into the CI errors? Feel free to ping me if there's anything I can help.

@david-cortes
Copy link
Contributor Author

Hi, could you please help take a look into the CI errors? Feel free to ping me if there's anything I can help.

This is the message I managed to find:

XFAIL tests/python/test_with_modin.py::TestModin::test_modin

The PR didn't touch anything that would deal with modin so don't know the reason for the failure.

@trivialfis
Copy link
Member

trivialfis commented Nov 1, 2023

This is the message I managed to find:

Hmm, not sure where did you see the modin error. Here are the ones I see on github action:

https://github.com/dmlc/xgboost/actions/runs/6719062791/job/18259950760?pr=9743
https://github.com/dmlc/xgboost/actions/runs/6719062791/job/18259951139?pr=9743
https://github.com/dmlc/xgboost/actions/runs/6719062791/job/18259950609?pr=9743

 ================================== FAILURES ===================================
__________________________ test_sklearn_random_state __________________________

    def test_sklearn_random_state():
        clf = xgb.XGBClassifier(random_state=402)
        assert clf.get_xgb_params()['random_state'] == 402
    
        clf = xgb.XGBClassifier(random_state=401)
        assert clf.get_xgb_params()['random_state'] == 401
    
        random_state = np.random.RandomState(seed=403)
        clf = xgb.XGBClassifier(random_state=random_state)
        assert isinstance(clf.get_xgb_params()['random_state'], int)
    
        random_state = np.random.default_rng(seed=404)
        clf = xgb.XGBClassifier(random_state=random_state)
>       assert isinstance(clf.get_xgb_params()['random_state'], int)
E       assert False
E        +  where False = isinstance(1983313941, int)

@david-cortes
Copy link
Contributor Author

Thanks for the hints. Fixed now.

@hcho3 hcho3 merged commit be20df8 into dmlc:master Nov 1, 2023
26 checks passed
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.

3 participants