xgboost_wrapper#
- class coffea.ml_tools.xgboost_wrapper(fname)[source]#
Bases:
numpy_call_wrapper,nonserializable_attributeVery simple wrapper for xgbooster inference. The xgboost.Booster object is nonserializable, so the users should pass in the xgboost model file.
- Parameters:
fname (
str) – Path to the xgboost model file, such that anxgboostercan be created viaxgboost.Booster(model_file=fname).
Methods Summary
numpy_call(data[, dmat_args, predict_args])Pass the numpy array data as-is to the construction of an xgboost.DMatrix constructor (with additional keyword arguments should they be specified), then run the xgboost.Booster.predict method (with additional keyword arguments).
validate_numpy_input(data[, dmat_args, ...])Check that the arguments to be passed into the actual xgboost inference request are valid.
Methods Documentation
- numpy_call(data: ndarray, dmat_args: dict | None = None, predict_args: dict | None = None)[source]#
Pass the numpy array data as-is to the construction of an xgboost.DMatrix constructor (with additional keyword arguments should they be specified), then run the xgboost.Booster.predict method (with additional keyword arguments).
- Parameters:
data (
numpy.ndarray) – The data to pass into thexgboost.DMatrixconstruction.dmat_args (
dict[str,str], optional) – Keyword arguments to pass into thexgboost.DMatrixconstruction.predict_args (
dict[str,str], optional) – Keyword arguments to pass to the actual prediction step ofxgboost, ie: thepredictmethod ofxgbooster.Booster.predict. Note that the first argument of that method is handled by this method.
- validate_numpy_input(data: ndarray, dmat_args: dict | None = None, predict_args: dict | None = None)[source]#
Check that the arguments to be passed into the actual xgboost inference request are valid.
The inner most dimension of the data array should be smaller than the number of features of the xgboost model. (Will raise a warning if mismatched). We will not attempt to parse the kwargs passed to the construction of a DMatrix, or the predict call, as those advanced features are expected to be properly handled by the user.
- Parameters:
data (
numpy.ndarray) – The data to pass into thexgboost.DMatrixconstruction.dmat_args (
dict[str,str], optional) – Keyword arguments to pass into thexgboost.DMatrixconstruction.predict_args (
dict[str,str], optional) – Keyword arguments to pass to the actual prediction step ofxgboost, ie: thepredictmethod ofxgbooster.Booster.predict. Note that the first argument of that method is handled by this method.