.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_successive_halving_iterations.py: Successive Halving ================== .. image:: /auto_examples/images/sphx_glr_plot_successive_halving_iterations_001.png :alt: Candidate scores over iterations :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/circleci/miniconda/envs/testenv/lib/python3.8/site-packages/sklearn/utils/validation.py:67: FutureWarning: Pass random_state=RandomState(MT19937) as keyword args. From version 0.25 passing these as positional arguments will result in an error warnings.warn("Pass {} as keyword args. From version 0.25 " /home/circleci/project/examples/plot_successive_halving_iterations.py:47: UserWarning: FixedFormatter should only be used together with FixedLocator ax.set_xticklabels(labels) | .. code-block:: default import pandas as pd from sklearn import datasets import matplotlib.pyplot as plt from sklearn.ensemble import RandomForestClassifier from scipy.stats import randint import numpy as np from dabl.search import RandomSuccessiveHalving rng = np.random.RandomState(0) X, y = datasets.make_classification(n_samples=700, random_state=rng) clf = RandomForestClassifier(n_estimators=20, random_state=rng) param_dist = {"max_depth": [3, None], "max_features": randint(1, 11), "min_samples_split": randint(2, 11), "bootstrap": [True, False], "criterion": ["gini", "entropy"]} rsh = RandomSuccessiveHalving( estimator=clf, param_distributions=param_dist, budget_on='n_samples', # budget is the number of samples max_budget='auto', # max_budget=n_samples n_candidates='auto', # choose n_cdts so that last iter exhausts budget cv=5, ratio=2, random_state=rng) rsh.fit(X, y) results = pd.DataFrame(rsh.cv_results_) results['params_str'] = results.params.apply(str) mean_scores = results.pivot(index='iter', columns='params_str', values='mean_test_score') ax = mean_scores.plot(legend=False, alpha=.6) r_i_list = results.groupby('iter').r_i.unique() labels = ['{}\nn_samples={}'.format(i, r_i_list[i]) for i in range(rsh.n_iterations_)] ax.set_xticklabels(labels) ax.set_title('Candidate scores over iterations') ax.set_ylabel('score') plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 8.893 seconds) .. _sphx_glr_download_auto_examples_plot_successive_halving_iterations.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_successive_halving_iterations.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_successive_halving_iterations.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_