Free AI web copilot to create summaries, insights and extended knowledge, download it at here
3938
Abstract
/a> is also <b>fast</b>. To see this, we benchmark <a href="https://github.com/ray-project/tune-sklearn">tune-sklearn</a> (with early stopping enabled) against native Scikit-Learn on a standard hyperparameter sweep. In our benchmarks we can see significant performance differences on both an average laptop and a large workstation of 48 CPU cores.</p><p id="2b1f">For the larger benchmark 48-core computer, Scikit-Learn took 20 minutes for a 40,000-size dataset searching over 75 hyperparameter sets. <a href="https://github.com/ray-project/tune-sklearn">Tune-sklearn </a>took a mere 3 and a half minutes — sacrificing minimal accuracy.</p><figure id="d388"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*7nWc03v4QLEKaF3iHkJPFA.png"><figcaption></figcaption></figure><figure id="01d2"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*DcXUJOjaX7lhQol4apE33g.png"><figcaption>On left: On a personal dual core i5 8GB RAM laptop using a parameter grid of 6 configurations. On right: On a large 48 core 250 GB RAM computer using a parameter grid of 75 configurations. Edit 7/19/2020: We took out a couple benchmarked libraries because we found an experimental error</figcaption></figure><p id="be0b"><i> Note: For smaller datasets (10,000 or fewer data points), there may be a sacrifice in accuracy when attempting to fit with early stopping. We don’t anticipate this to make a difference for users as the library is intended to speed up large training tasks with large datasets.</i></p><h1 id="d88a">Simple 60 second Walkthrough</h1><p id="4a87">Let’s take a look at how it all works.</p><p id="7e9a">Run <code>pip install tune-sklearn ray[tune]</code> or <code>pip install tune-sklearn "ray[tune]"</code>to get started with our example code below.</p><figure id="4325"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*yvXlXlEqR4wQLIwkHwpHFQ.gif"><figcaption><i>Hyperparam set 2 is a set of unpromising hyperparameters that would be detected by tune’s early stopping mechanisms, and stopped early to avoid wasting training time and resources.</i></figcaption></figure><h2 id="2a72">TuneGridSearchCV Example</h2><p id="ecc9">To start out, it’s as easy as changing our import statement to get Tune’s grid search cross validation interface:</p>
<figure id="310d">
<div>
<div>
<iframe class="gist-iframe" src="/gist/inventormc/e17831add0ec16158e9cc52b06c50f2f.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="9256">And from there, we would proceed just like how we would in Scikit-Learn’s interface! Let’s use a “dummy” custom classification dataset and an <code>SGDClassifier</code> to classify the data.</p><p id="8a23">We choose the <code>SGDClassifier</code> because it has a <code>partial_fit</code> API, which enables it to stop fitting to the data for a certain hyperparameter configuration. If the estimator does not support early stopping, we would fall back to a parallel grid search.</p>
<figure id="6d1c">
<div>
<div>
<iframe class="gist-iframe" src="/gist/inventormc/1c852b46d1403ba9316b48cd6d7df18a.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="cedf">As you can see, the setup here is exactly how you would do it for Scikit-Learn! Now, let’s try fitting a model.</p>
<figure id="53f0">
<div>
<div>
<iframe class="gist-iframe" src="/gist/inventormc/0937969a2c724284b33219668eb77b7b.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div
Options
</div></figure><p id="e9eb">Note the slight differences we introduced above:</p><ol><li>a new <code>early_stopping</code> variable, and</li><li>a specification of <code>max_iters</code> parameter</li></ol><p id="e615">The <code>early_stopping</code> determines when to stop early — MedianStoppingRule is a great default but see Tune’s documentation on schedulers <a href="https://docs.ray.io/en/master/tune-schedulers.html">here</a> for a full list to choose from. <code>max_iters</code> is the maximum number of iterations a given hyperparameter set <i>could</i> run for; it may run for fewer iterations if it is early stopped.</p><p id="1957">Try running this compared to the GridSearchCV equivalent.</p>
<figure id="96c4">
<div>
<div>
<iframe class="gist-iframe" src="/gist/inventormc/84616c853ad1c0a30e42a25a17b17046.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><h2 id="1788">TuneSearchCV Bayesian Optimization Example</h2><p id="3e2e">Other than the grid search interface, <a href="https://github.com/ray-project/tune-sklearn">tune-sklearn</a> also provides an interface, TuneSearchCV, for sampling from distributions of hyperparameters.</p><p id="05ec">In addition, you can easily enable Bayesian optimization over the distributions in TuneSearchCV in only a few lines of code changes.</p><p id="99b2">Run <code>pip install scikit-optimize</code> to try out this example:</p>
<figure id="4844">
<div>
<div>
<iframe class="gist-iframe" src="/gist/inventormc/f91491af06a9ece17d3a483543ac9cb8.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="c8a5">As you can see, it’s very simple to integrate <a href="https://github.com/ray-project/tune-sklearn">tune-sklearn</a> into existing code. You can check out more detailed examples and get started with <a href="https://github.com/ray-project/tune-sklearn">tune-sklearn here</a>. Also take a look at Ray’s <a href="https://readmedium.com/easy-distributed-scikit-learn-training-with-ray-54ff8b643b33">replacement</a> for joblib, which allows users to parallelize training over multiple nodes, not just one node, further speeding up training. If you have any questions or thoughts about tune-sklearn, you can join our community through <a href="https://discuss.ray.io/">Discourse</a> or <a href="https://docs.google.com/forms/d/e/1FAIpQLSfAcoiLCHOguOm8e7Jnn-JJdZaCxPGjgVCvFijHB5PLaQLeig/viewform">Slack</a>. If you would like to see how Ray Tune is being used throughout industry, consider joining us at <a href="http://anyscale.com/ray-summit">Ray Summit</a>.</p><h2 id="fc09">Documentation and Examples</h2><ul><li><a href="https://docs.ray.io/en/master/tune/api_docs/sklearn.html">Documentation</a>*</li><li>Example: <a href="https://github.com/ray-project/tune-sklearn/blob/master/examples/torch_nn.py">Skorch with tune-sklearn</a></li><li>Example: <a href="https://github.com/ray-project/tune-sklearn/blob/master/examples/sklearn_pipeline.py">Scikit-Learn Pipelines with tune-sklearn</a></li><li>Example: <a href="https://github.com/ray-project/tune-sklearn/blob/master/examples/xgbclassifier.py">XGBoost with tune-sklearn</a></li><li>Example: <a href="https://github.com/ray-project/tune-sklearn/blob/master/examples/keras_example.py">KerasClassifier with tune-sklearn</a></li><li>Example: <a href="https://github.com/ray-project/tune-sklearn/blob/master/examples/lgbm.py">LightGBM with tune-sklearn</a></li></ul><p id="dc5f"><i>Note: importing from <code>ray.tune</code> as shown in the linked documentation is available only on the nightly Ray wheels and will be available on pip soon.</i></p></article></body>