[doc] Include dask examples into doc. (#7530)

This commit is contained in:
Jiaming Yuan
2022-01-05 03:27:22 +08:00
committed by GitHub
parent 54582f641a
commit ec56d5869b
13 changed files with 74 additions and 47 deletions

View File

@@ -1,6 +1,7 @@
'''Dask interface demo:
Use scikit-learn regressor interface with CPU histogram tree method.'''
"""
Use scikit-learn regressor interface with CPU histogram tree method
===================================================================
"""
from dask.distributed import Client
from dask.distributed import LocalCluster
from dask import array as da
@@ -16,7 +17,7 @@ def main(client):
y = da.random.random(m, partition_size)
regressor = xgboost.dask.DaskXGBRegressor(verbosity=1, n_estimators=2)
regressor.set_params(tree_method='hist')
regressor.set_params(tree_method="hist")
# assigning client here is optional
regressor.client = client
@@ -26,13 +27,13 @@ def main(client):
bst = regressor.get_booster()
history = regressor.evals_result()
print('Evaluation history:', history)
print("Evaluation history:", history)
# returned prediction is always a dask array.
assert isinstance(prediction, da.Array)
return bst # returning the trained model
return bst # returning the trained model
if __name__ == '__main__':
if __name__ == "__main__":
# or use other clusters for scaling
with LocalCluster(n_workers=4, threads_per_worker=1) as cluster:
with Client(cluster) as client: