.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "python/examples/sklearn_parallel.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_python_examples_sklearn_parallel.py: Demo for using xgboost with sklearn =================================== .. GENERATED FROM PYTHON SOURCE LINES 5-29 .. code-block:: Python import multiprocessing from sklearn.datasets import fetch_california_housing from sklearn.model_selection import GridSearchCV import xgboost as xgb if __name__ == "__main__": print("Parallel Parameter optimization") X, y = fetch_california_housing(return_X_y=True) # Make sure the number of threads is balanced. xgb_model = xgb.XGBRegressor( n_jobs=multiprocessing.cpu_count() // 2, tree_method="hist" ) clf = GridSearchCV( xgb_model, {"max_depth": [2, 4, 6], "n_estimators": [50, 100, 200]}, verbose=1, n_jobs=2, ) clf.fit(X, y) print(clf.best_score_) print(clf.best_params_) .. _sphx_glr_download_python_examples_sklearn_parallel.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sklearn_parallel.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sklearn_parallel.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: sklearn_parallel.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_