Don't set_params at the end of set_state. (#4947)

* Don't set_params at the end of set_state.

* Also fix another issue found in dask prediction.

* Add note about prediction.

Don't support other prediction modes at the moment.
This commit is contained in:
Jiaming Yuan
2019-10-15 10:08:26 -04:00
committed by GitHub
parent 2ebdec8aa6
commit 7e72a12871
6 changed files with 70 additions and 8 deletions

View File

@@ -1125,7 +1125,6 @@ class Booster(object):
_check_call(_LIB.XGBoosterLoadModelFromBuffer(handle, ptr, length))
state['handle'] = handle
self.__dict__.update(state)
self.set_param({'seed': 0})
def __copy__(self):
return self.__deepcopy__(None)

View File

@@ -395,6 +395,10 @@ def train(client, params, dtrain, *args, evals=(), **kwargs):
def predict(client, model, data, *args):
'''Run prediction with a trained booster.
.. note::
Only default prediction mode is supported right now.
Parameters
----------
client: dask.distributed.Client
@@ -445,8 +449,8 @@ def predict(client, model, data, *args):
'''Get shape of data in each worker.'''
logging.info('Trying to get data shape on %d', worker_id)
worker = distributed_get_worker()
rows, cols = data.get_worker_data_shape(worker)
return rows, cols
rows, _ = data.get_worker_data_shape(worker)
return rows, 1 # default is 1
# Constructing a dask array from list of numpy arrays
# See https://docs.dask.org/en/latest/array-creation.html
@@ -457,7 +461,7 @@ def predict(client, model, data, *args):
shapes = client.gather(futures_shape)
arrays = []
for i in range(len(futures_shape)):
arrays.append(da.from_delayed(futures[i], shape=shapes[i],
arrays.append(da.from_delayed(futures[i], shape=(shapes[i][0], ),
dtype=numpy.float32))
predictions = da.concatenate(arrays, axis=0)
return predictions