Scikit-Learn`hasanexistingmoduleformodelselection<https://scikit-learn.org/stable/modules/grid_search.html>`_,butthealgorithmsoffered(GridSearch/``GridSearchCV``andRandomSearch/``RandomizedSearchCV``)areoftenconsideredinefficient.Inthistutorial,we'll cover ``tune-sklearn``, a drop-in replacement for Scikit-Learn'smodelselectionmodulewithstate-of-the-artoptimizationfeaturessuchasearlystoppingandBayesianOptimization.
``tune-sklearn``isamodulethatintegratesRayTune's hyperparameter tuning and scikit-learn'sClassifierAPI.``tune-sklearn``hastwoAPIs::ref:`TuneSearchCV<tunesearchcv-docs>`,and:ref:`TuneGridSearchCV<tunegridsearchcv-docs>`.Theyaredrop-inreplacementsforScikit-learn's RandomizedSearchCV and GridSearchCV, so you only need to change less than 5 lines in a standard Scikit-Learn script to use the API.
RayTune's Scikit-learn APIs allows you to easily leverage Bayesian Optimization, HyperBand, and other cutting edge tuning techniques by simply toggling a few parameters. It also supports and provides examples for many other frameworks with Scikit-Learn wrappers such as Skorch (Pytorch), KerasClassifiers (Keras), and XGBoostClassifiers (XGBoost).
# In addition to the grid search interface, tune-sklearn also provides an interface, TuneSearchCV, for sampling from **distributions of hyperparameters**.
#
# In addition, you can easily enable Bayesian optimization over the distributions in only 2 lines of code:
# As you can see, it’s very simple to integrate tune-sklearn into existing code. Distributed execution is also easy - you can simply run ``ray.init(address="auto")`` before
# TuneSearchCV to connect to the Ray cluster and parallelize tuning across multiple nodes, as you would in any other Ray Tune script.
#
#
# Code Examples
# -------------
#
# Check out more detailed examples and get started with tune-sklearn!
#
# * `Skorch with tune-sklearn <https://github.com/ray-project/tune-sklearn/blob/master/examples/torch_nn.py>`_
# * `Scikit-Learn Pipelines with tune-sklearn <https://github.com/ray-project/tune-sklearn/blob/master/examples/sklearn_pipeline.py>`_
# * `XGBoost with tune-sklearn <https://github.com/ray-project/tune-sklearn/blob/master/examples/xgbclassifier.py>`_
# * `KerasClassifier with tune-sklearn <https://github.com/ray-project/tune-sklearn/blob/master/examples/keras_example.py>`_
# * `LightGBM with tune-sklearn <https://github.com/ray-project/tune-sklearn/blob/master/examples/lgbm.py>`_
#
#
# Further Reading
# ---------------
#
# If you're using scikit-learn for other tasks, take a look at Ray’s :ref:`replacement for joblib <ray-joblib>`, which allows users to parallelize scikit learn jobs over multiple nodes.