Note

Go to the endto download the full example code.

Use scikit-learn regressor interface with CPU histogram tree method

fromdaskimportarrayasdafromdask.distributedimportClient,LocalClusterfromxgboostimportdaskasdxgbdefmain(client:Client)->dxgb.Booster:# generate some random data for demonstrationn=100m=10000partition_size=100X=da.random.random((m,n),partition_size)y=da.random.random(m,partition_size)regressor=dxgb.DaskXGBRegressor(verbosity=1,n_estimators=2)regressor.set_params(tree_method="hist")# assigning client here is optionalregressor.client=clientregressor.fit(X,y,eval_set=[(X,y)])prediction=regressor.predict(X)bst=regressor.get_booster()history=regressor.evals_result()print("Evaluation history:",history)# returned prediction is always a dask array.assertisinstance(prediction,da.Array)returnbst# returning the trained modelif__name__=="__main__":# or use other clusters for scalingwithLocalCluster(n_workers=4,threads_per_worker=1)ascluster:withClient(cluster)asclient:main(client)

Gallery generated by Sphinx-Gallery