Merge branch 'master' into sync-condition-2023Apr11
This commit is contained in:
@@ -23,13 +23,7 @@ from typing import (
|
||||
import numpy
|
||||
|
||||
from . import collective
|
||||
from .core import (
|
||||
Booster,
|
||||
DMatrix,
|
||||
XGBoostError,
|
||||
_get_booster_layer_trees,
|
||||
_parse_eval_str,
|
||||
)
|
||||
from .core import Booster, DMatrix, XGBoostError, _parse_eval_str
|
||||
|
||||
__all__ = [
|
||||
"TrainingCallback",
|
||||
@@ -177,22 +171,14 @@ class CallbackContainer:
|
||||
assert isinstance(model, Booster), msg
|
||||
|
||||
if not self.is_cv:
|
||||
num_parallel_tree, _ = _get_booster_layer_trees(model)
|
||||
if model.attr("best_score") is not None:
|
||||
model.best_score = float(cast(str, model.attr("best_score")))
|
||||
model.best_iteration = int(cast(str, model.attr("best_iteration")))
|
||||
# num_class is handled internally
|
||||
model.set_attr(
|
||||
best_ntree_limit=str((model.best_iteration + 1) * num_parallel_tree)
|
||||
)
|
||||
model.best_ntree_limit = int(cast(str, model.attr("best_ntree_limit")))
|
||||
else:
|
||||
# Due to compatibility with version older than 1.4, these attributes are
|
||||
# added to Python object even if early stopping is not used.
|
||||
model.best_iteration = model.num_boosted_rounds() - 1
|
||||
model.set_attr(best_iteration=str(model.best_iteration))
|
||||
model.best_ntree_limit = (model.best_iteration + 1) * num_parallel_tree
|
||||
model.set_attr(best_ntree_limit=str(model.best_ntree_limit))
|
||||
|
||||
return model
|
||||
|
||||
|
||||
@@ -94,9 +94,9 @@ def from_cstr_to_pystr(data: CStrPptr, length: c_bst_ulong) -> List[str]:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
data : ctypes pointer
|
||||
data :
|
||||
pointer to data
|
||||
length : ctypes pointer
|
||||
length :
|
||||
pointer to length of data
|
||||
"""
|
||||
res = []
|
||||
@@ -126,33 +126,14 @@ def _parse_eval_str(result: str) -> List[Tuple[str, float]]:
|
||||
IterRange = TypeVar("IterRange", Optional[Tuple[int, int]], Tuple[int, int])
|
||||
|
||||
|
||||
def _convert_ntree_limit(
|
||||
booster: "Booster", ntree_limit: Optional[int], iteration_range: IterRange
|
||||
) -> IterRange:
|
||||
if ntree_limit is not None and ntree_limit != 0:
|
||||
warnings.warn(
|
||||
"ntree_limit is deprecated, use `iteration_range` or model "
|
||||
"slicing instead.",
|
||||
UserWarning,
|
||||
)
|
||||
if iteration_range is not None and iteration_range[1] != 0:
|
||||
raise ValueError(
|
||||
"Only one of `iteration_range` and `ntree_limit` can be non zero."
|
||||
)
|
||||
num_parallel_tree, _ = _get_booster_layer_trees(booster)
|
||||
num_parallel_tree = max([num_parallel_tree, 1])
|
||||
iteration_range = (0, ntree_limit // num_parallel_tree)
|
||||
return iteration_range
|
||||
|
||||
|
||||
def _expect(expectations: Sequence[Type], got: Type) -> str:
|
||||
"""Translate input error into string.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
expectations: sequence
|
||||
expectations :
|
||||
a list of expected value.
|
||||
got:
|
||||
got :
|
||||
actual input
|
||||
|
||||
Returns
|
||||
@@ -282,7 +263,7 @@ def _check_call(ret: int) -> None:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
ret : int
|
||||
ret :
|
||||
return value from API calls
|
||||
"""
|
||||
if ret != 0:
|
||||
@@ -290,10 +271,10 @@ def _check_call(ret: int) -> None:
|
||||
|
||||
|
||||
def build_info() -> dict:
|
||||
"""Build information of XGBoost. The returned value format is not stable. Also, please
|
||||
note that build time dependency is not the same as runtime dependency. For instance,
|
||||
it's possible to build XGBoost with older CUDA version but run it with the lastest
|
||||
one.
|
||||
"""Build information of XGBoost. The returned value format is not stable. Also,
|
||||
please note that build time dependency is not the same as runtime dependency. For
|
||||
instance, it's possible to build XGBoost with older CUDA version but run it with the
|
||||
lastest one.
|
||||
|
||||
.. versionadded:: 1.6.0
|
||||
|
||||
@@ -677,28 +658,28 @@ class DMatrix: # pylint: disable=too-many-instance-attributes,too-many-public-m
|
||||
data :
|
||||
Data source of DMatrix. See :ref:`py-data` for a list of supported input
|
||||
types.
|
||||
label : array_like
|
||||
label :
|
||||
Label of the training data.
|
||||
weight : array_like
|
||||
weight :
|
||||
Weight for each instance.
|
||||
|
||||
.. note:: For ranking task, weights are per-group.
|
||||
.. note::
|
||||
|
||||
In ranking task, one weight is assigned to each group (not each
|
||||
data point). This is because we only care about the relative
|
||||
ordering of data points within each group, so it doesn't make
|
||||
sense to assign weights to individual data points.
|
||||
For ranking task, weights are per-group. In ranking task, one weight
|
||||
is assigned to each group (not each data point). This is because we
|
||||
only care about the relative ordering of data points within each group,
|
||||
so it doesn't make sense to assign weights to individual data points.
|
||||
|
||||
base_margin: array_like
|
||||
base_margin :
|
||||
Base margin used for boosting from existing model.
|
||||
missing : float, optional
|
||||
Value in the input data which needs to be present as a missing
|
||||
value. If None, defaults to np.nan.
|
||||
silent : boolean, optional
|
||||
missing :
|
||||
Value in the input data which needs to be present as a missing value. If
|
||||
None, defaults to np.nan.
|
||||
silent :
|
||||
Whether print messages during construction
|
||||
feature_names : list, optional
|
||||
feature_names :
|
||||
Set names for features.
|
||||
feature_types : FeatureTypes
|
||||
feature_types :
|
||||
|
||||
Set types for features. When `enable_categorical` is set to `True`, string
|
||||
"c" represents categorical data type while "q" represents numerical feature
|
||||
@@ -708,20 +689,20 @@ class DMatrix: # pylint: disable=too-many-instance-attributes,too-many-public-m
|
||||
`.cat.codes` method. This is useful when users want to specify categorical
|
||||
features without having to construct a dataframe as input.
|
||||
|
||||
nthread : integer, optional
|
||||
nthread :
|
||||
Number of threads to use for loading data when parallelization is
|
||||
applicable. If -1, uses maximum threads available on the system.
|
||||
group : array_like
|
||||
group :
|
||||
Group size for all ranking group.
|
||||
qid : array_like
|
||||
qid :
|
||||
Query ID for data samples, used for ranking.
|
||||
label_lower_bound : array_like
|
||||
label_lower_bound :
|
||||
Lower bound for survival training.
|
||||
label_upper_bound : array_like
|
||||
label_upper_bound :
|
||||
Upper bound for survival training.
|
||||
feature_weights : array_like, optional
|
||||
feature_weights :
|
||||
Set feature weights for column sampling.
|
||||
enable_categorical: boolean, optional
|
||||
enable_categorical :
|
||||
|
||||
.. versionadded:: 1.3.0
|
||||
|
||||
@@ -1508,41 +1489,6 @@ Objective = Callable[[np.ndarray, DMatrix], Tuple[np.ndarray, np.ndarray]]
|
||||
Metric = Callable[[np.ndarray, DMatrix], Tuple[str, float]]
|
||||
|
||||
|
||||
def _get_booster_layer_trees(model: "Booster") -> Tuple[int, int]:
|
||||
"""Get number of trees added to booster per-iteration. This function will be removed
|
||||
once `best_ntree_limit` is dropped in favor of `best_iteration`. Returns
|
||||
`num_parallel_tree` and `num_groups`.
|
||||
|
||||
"""
|
||||
config = json.loads(model.save_config())
|
||||
booster = config["learner"]["gradient_booster"]["name"]
|
||||
if booster == "gblinear":
|
||||
num_parallel_tree = 0
|
||||
elif booster == "dart":
|
||||
num_parallel_tree = int(
|
||||
config["learner"]["gradient_booster"]["gbtree"]["gbtree_model_param"][
|
||||
"num_parallel_tree"
|
||||
]
|
||||
)
|
||||
elif booster == "gbtree":
|
||||
try:
|
||||
num_parallel_tree = int(
|
||||
config["learner"]["gradient_booster"]["gbtree_model_param"][
|
||||
"num_parallel_tree"
|
||||
]
|
||||
)
|
||||
except KeyError:
|
||||
num_parallel_tree = int(
|
||||
config["learner"]["gradient_booster"]["gbtree_train_param"][
|
||||
"num_parallel_tree"
|
||||
]
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"Unknown booster: {booster}")
|
||||
num_groups = int(config["learner"]["learner_model_param"]["num_class"])
|
||||
return num_parallel_tree, num_groups
|
||||
|
||||
|
||||
def _configure_metrics(params: BoosterParam) -> BoosterParam:
|
||||
if (
|
||||
isinstance(params, dict)
|
||||
@@ -1576,11 +1522,11 @@ class Booster:
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
params : dict
|
||||
params :
|
||||
Parameters for boosters.
|
||||
cache : list
|
||||
cache :
|
||||
List of cache items.
|
||||
model_file : string/os.PathLike/Booster/bytearray
|
||||
model_file :
|
||||
Path to the model file if it's string or PathLike.
|
||||
"""
|
||||
cache = cache if cache is not None else []
|
||||
@@ -1766,6 +1712,7 @@ class Booster:
|
||||
string.
|
||||
|
||||
.. versionadded:: 1.0.0
|
||||
|
||||
"""
|
||||
json_string = ctypes.c_char_p()
|
||||
length = c_bst_ulong()
|
||||
@@ -1798,8 +1745,8 @@ class Booster:
|
||||
|
||||
Returns
|
||||
-------
|
||||
booster: `Booster`
|
||||
a copied booster model
|
||||
booster :
|
||||
A copied booster model
|
||||
"""
|
||||
return copy.copy(self)
|
||||
|
||||
@@ -1808,12 +1755,12 @@ class Booster:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
key : str
|
||||
key :
|
||||
The key to get attribute from.
|
||||
|
||||
Returns
|
||||
-------
|
||||
value : str
|
||||
value :
|
||||
The attribute value of the key, returns None if attribute do not exist.
|
||||
"""
|
||||
ret = ctypes.c_char_p()
|
||||
@@ -1932,9 +1879,9 @@ class Booster:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
params: dict/list/str
|
||||
params :
|
||||
list of key,value pairs, dict of key to value or simply str key
|
||||
value: optional
|
||||
value :
|
||||
value of the specified parameter, when params is str key
|
||||
"""
|
||||
if isinstance(params, Mapping):
|
||||
@@ -1957,11 +1904,11 @@ class Booster:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
dtrain : DMatrix
|
||||
dtrain :
|
||||
Training data.
|
||||
iteration : int
|
||||
iteration :
|
||||
Current iteration number.
|
||||
fobj : function
|
||||
fobj :
|
||||
Customized objective function.
|
||||
|
||||
"""
|
||||
@@ -2100,7 +2047,6 @@ class Booster:
|
||||
self,
|
||||
data: DMatrix,
|
||||
output_margin: bool = False,
|
||||
ntree_limit: int = 0,
|
||||
pred_leaf: bool = False,
|
||||
pred_contribs: bool = False,
|
||||
approx_contribs: bool = False,
|
||||
@@ -2127,9 +2073,6 @@ class Booster:
|
||||
output_margin :
|
||||
Whether to output the raw untransformed margin value.
|
||||
|
||||
ntree_limit :
|
||||
Deprecated, use `iteration_range` instead.
|
||||
|
||||
pred_leaf :
|
||||
When this option is on, the output will be a matrix of (nsample,
|
||||
ntrees) with each record indicating the predicted leaf index of
|
||||
@@ -2196,7 +2139,6 @@ class Booster:
|
||||
raise TypeError("Expecting data to be a DMatrix object, got: ", type(data))
|
||||
if validate_features:
|
||||
self._validate_dmatrix_features(data)
|
||||
iteration_range = _convert_ntree_limit(self, ntree_limit, iteration_range)
|
||||
args = {
|
||||
"type": 0,
|
||||
"training": training,
|
||||
@@ -2264,8 +2206,7 @@ class Booster:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
data : numpy.ndarray/scipy.sparse.csr_matrix/cupy.ndarray/
|
||||
cudf.DataFrame/pd.DataFrame
|
||||
data :
|
||||
The input data, must not be a view for numpy array. Set
|
||||
``predictor`` to ``gpu_predictor`` for running prediction on CuPy
|
||||
array or CuDF DataFrame.
|
||||
@@ -2449,7 +2390,7 @@ class Booster:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fname : string or os.PathLike
|
||||
fname :
|
||||
Output file name
|
||||
|
||||
"""
|
||||
@@ -2522,8 +2463,6 @@ class Booster:
|
||||
self.best_iteration = int(self.attr("best_iteration")) # type: ignore
|
||||
if self.attr("best_score") is not None:
|
||||
self.best_score = float(self.attr("best_score")) # type: ignore
|
||||
if self.attr("best_ntree_limit") is not None:
|
||||
self.best_ntree_limit = int(self.attr("best_ntree_limit")) # type: ignore
|
||||
|
||||
def num_boosted_rounds(self) -> int:
|
||||
"""Get number of boosted rounds. For gblinear this is reset to 0 after
|
||||
@@ -2555,13 +2494,13 @@ class Booster:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fout : string or os.PathLike
|
||||
fout :
|
||||
Output file name.
|
||||
fmap : string or os.PathLike, optional
|
||||
fmap :
|
||||
Name of the file containing feature map names.
|
||||
with_stats : bool, optional
|
||||
with_stats :
|
||||
Controls whether the split statistics are output.
|
||||
dump_format : string, optional
|
||||
dump_format :
|
||||
Format of model dump file. Can be 'text' or 'json'.
|
||||
"""
|
||||
if isinstance(fout, (str, os.PathLike)):
|
||||
@@ -2665,9 +2604,9 @@ class Booster:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fmap:
|
||||
fmap :
|
||||
The name of feature map file.
|
||||
importance_type:
|
||||
importance_type :
|
||||
One of the importance types defined above.
|
||||
|
||||
Returns
|
||||
@@ -2716,7 +2655,7 @@ class Booster:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fmap: str or os.PathLike (optional)
|
||||
fmap :
|
||||
The name of feature map file.
|
||||
"""
|
||||
# pylint: disable=too-many-locals
|
||||
@@ -2882,15 +2821,15 @@ class Booster:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
feature: str
|
||||
feature :
|
||||
The name of the feature.
|
||||
fmap: str or os.PathLike (optional)
|
||||
fmap:
|
||||
The name of feature map file.
|
||||
bin: int, default None
|
||||
bin :
|
||||
The maximum number of bins.
|
||||
Number of bins equals number of unique split values n_unique,
|
||||
if bins == None or bins > n_unique.
|
||||
as_pandas: bool, default True
|
||||
as_pandas :
|
||||
Return pd.DataFrame when pandas is installed.
|
||||
If False or pandas is not installed, return numpy ndarray.
|
||||
|
||||
|
||||
@@ -1653,14 +1653,11 @@ class DaskScikitLearnBase(XGBModel):
|
||||
self,
|
||||
X: _DataT,
|
||||
output_margin: bool = False,
|
||||
ntree_limit: Optional[int] = None,
|
||||
validate_features: bool = True,
|
||||
base_margin: Optional[_DaskCollection] = None,
|
||||
iteration_range: Optional[Tuple[int, int]] = None,
|
||||
) -> Any:
|
||||
_assert_dask_support()
|
||||
msg = "`ntree_limit` is not supported on dask, use `iteration_range` instead."
|
||||
assert ntree_limit is None, msg
|
||||
return self.client.sync(
|
||||
self._predict_async,
|
||||
X,
|
||||
@@ -1694,12 +1691,9 @@ class DaskScikitLearnBase(XGBModel):
|
||||
def apply(
|
||||
self,
|
||||
X: _DataT,
|
||||
ntree_limit: Optional[int] = None,
|
||||
iteration_range: Optional[Tuple[int, int]] = None,
|
||||
) -> Any:
|
||||
_assert_dask_support()
|
||||
msg = "`ntree_limit` is not supported on dask, use `iteration_range` instead."
|
||||
assert ntree_limit is None, msg
|
||||
return self.client.sync(self._apply_async, X, iteration_range=iteration_range)
|
||||
|
||||
def __await__(self) -> Awaitable[Any]:
|
||||
@@ -1993,14 +1987,11 @@ class DaskXGBClassifier(DaskScikitLearnBase, XGBClassifierMixIn, XGBClassifierBa
|
||||
def predict_proba(
|
||||
self,
|
||||
X: _DaskCollection,
|
||||
ntree_limit: Optional[int] = None,
|
||||
validate_features: bool = True,
|
||||
base_margin: Optional[_DaskCollection] = None,
|
||||
iteration_range: Optional[Tuple[int, int]] = None,
|
||||
) -> Any:
|
||||
_assert_dask_support()
|
||||
msg = "`ntree_limit` is not supported on dask, use `iteration_range` instead."
|
||||
assert ntree_limit is None, msg
|
||||
return self._client_sync(
|
||||
self._predict_proba_async,
|
||||
X=X,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
# pylint: disable=too-many-locals, too-many-arguments, invalid-name,
|
||||
# pylint: disable=too-many-branches
|
||||
# coding: utf-8
|
||||
"""Plotting Library."""
|
||||
import json
|
||||
from io import BytesIO
|
||||
from typing import Any, Optional
|
||||
from typing import Any, Optional, Union
|
||||
|
||||
import numpy as np
|
||||
|
||||
@@ -17,7 +16,7 @@ GraphvizSource = Any # real type is graphviz.Source
|
||||
|
||||
|
||||
def plot_importance(
|
||||
booster: Booster,
|
||||
booster: Union[XGBModel, Booster, dict],
|
||||
ax: Optional[Axes] = None,
|
||||
height: float = 0.2,
|
||||
xlim: Optional[tuple] = None,
|
||||
@@ -37,40 +36,42 @@ def plot_importance(
|
||||
|
||||
Parameters
|
||||
----------
|
||||
booster : Booster, XGBModel or dict
|
||||
booster :
|
||||
Booster or XGBModel instance, or dict taken by Booster.get_fscore()
|
||||
ax : matplotlib Axes, default None
|
||||
ax : matplotlib Axes
|
||||
Target axes instance. If None, new figure and axes will be created.
|
||||
grid : bool, Turn the axes grids on or off. Default is True (On).
|
||||
importance_type : str, default "weight"
|
||||
grid :
|
||||
Turn the axes grids on or off. Default is True (On).
|
||||
importance_type :
|
||||
How the importance is calculated: either "weight", "gain", or "cover"
|
||||
|
||||
* "weight" is the number of times a feature appears in a tree
|
||||
* "gain" is the average gain of splits which use the feature
|
||||
* "cover" is the average coverage of splits which use the feature
|
||||
where coverage is defined as the number of samples affected by the split
|
||||
max_num_features : int, default None
|
||||
Maximum number of top features displayed on plot. If None, all features will be displayed.
|
||||
height : float, default 0.2
|
||||
max_num_features :
|
||||
Maximum number of top features displayed on plot. If None, all features will be
|
||||
displayed.
|
||||
height :
|
||||
Bar height, passed to ax.barh()
|
||||
xlim : tuple, default None
|
||||
xlim :
|
||||
Tuple passed to axes.xlim()
|
||||
ylim : tuple, default None
|
||||
ylim :
|
||||
Tuple passed to axes.ylim()
|
||||
title : str, default "Feature importance"
|
||||
title :
|
||||
Axes title. To disable, pass None.
|
||||
xlabel : str, default "F score"
|
||||
xlabel :
|
||||
X axis title label. To disable, pass None.
|
||||
ylabel : str, default "Features"
|
||||
ylabel :
|
||||
Y axis title label. To disable, pass None.
|
||||
fmap: str or os.PathLike (optional)
|
||||
fmap :
|
||||
The name of feature map file.
|
||||
show_values : bool, default True
|
||||
show_values :
|
||||
Show values on plot. To disable, pass False.
|
||||
values_format : str, default "{v}"
|
||||
Format string for values. "v" will be replaced by the value of the feature importance.
|
||||
e.g. Pass "{v:.2f}" in order to limit the number of digits after the decimal point
|
||||
to two, for each value printed on the graph.
|
||||
values_format :
|
||||
Format string for values. "v" will be replaced by the value of the feature
|
||||
importance. e.g. Pass "{v:.2f}" in order to limit the number of digits after
|
||||
the decimal point to two, for each value printed on the graph.
|
||||
kwargs :
|
||||
Other keywords passed to ax.barh()
|
||||
|
||||
@@ -146,7 +147,7 @@ def plot_importance(
|
||||
|
||||
|
||||
def to_graphviz(
|
||||
booster: Booster,
|
||||
booster: Union[Booster, XGBModel],
|
||||
fmap: PathLike = "",
|
||||
num_trees: int = 0,
|
||||
rankdir: Optional[str] = None,
|
||||
@@ -162,19 +163,19 @@ def to_graphviz(
|
||||
|
||||
Parameters
|
||||
----------
|
||||
booster : Booster, XGBModel
|
||||
booster :
|
||||
Booster or XGBModel instance
|
||||
fmap: str (optional)
|
||||
fmap :
|
||||
The name of feature map file
|
||||
num_trees : int, default 0
|
||||
num_trees :
|
||||
Specify the ordinal number of target tree
|
||||
rankdir : str, default "UT"
|
||||
rankdir :
|
||||
Passed to graphviz via graph_attr
|
||||
yes_color : str, default '#0000FF'
|
||||
yes_color :
|
||||
Edge color when meets the node condition.
|
||||
no_color : str, default '#FF0000'
|
||||
no_color :
|
||||
Edge color when doesn't meet the node condition.
|
||||
condition_node_params : dict, optional
|
||||
condition_node_params :
|
||||
Condition node configuration for for graphviz. Example:
|
||||
|
||||
.. code-block:: python
|
||||
@@ -183,7 +184,7 @@ def to_graphviz(
|
||||
'style': 'filled,rounded',
|
||||
'fillcolor': '#78bceb'}
|
||||
|
||||
leaf_node_params : dict, optional
|
||||
leaf_node_params :
|
||||
Leaf node configuration for graphviz. Example:
|
||||
|
||||
.. code-block:: python
|
||||
@@ -192,7 +193,7 @@ def to_graphviz(
|
||||
'style': 'filled',
|
||||
'fillcolor': '#e48038'}
|
||||
|
||||
\\*\\*kwargs: dict, optional
|
||||
kwargs :
|
||||
Other keywords passed to graphviz graph_attr, e.g. ``graph [ {key} = {value} ]``
|
||||
|
||||
Returns
|
||||
|
||||
@@ -36,7 +36,6 @@ from .core import (
|
||||
Objective,
|
||||
QuantileDMatrix,
|
||||
XGBoostError,
|
||||
_convert_ntree_limit,
|
||||
_deprecate_positional_args,
|
||||
_parse_eval_str,
|
||||
)
|
||||
@@ -391,8 +390,7 @@ __model_doc = f"""
|
||||
metric will be used for early stopping.
|
||||
|
||||
- If early stopping occurs, the model will have three additional fields:
|
||||
:py:attr:`best_score`, :py:attr:`best_iteration` and
|
||||
:py:attr:`best_ntree_limit`.
|
||||
:py:attr:`best_score`, :py:attr:`best_iteration`.
|
||||
|
||||
.. note::
|
||||
|
||||
@@ -1014,9 +1012,9 @@ class XGBModel(XGBModelBase):
|
||||
verbose :
|
||||
If `verbose` is True and an evaluation set is used, the evaluation metric
|
||||
measured on the validation set is printed to stdout at each boosting stage.
|
||||
If `verbose` is an integer, the evaluation metric is printed at each `verbose`
|
||||
boosting stage. The last boosting stage / the boosting stage found by using
|
||||
`early_stopping_rounds` is also printed.
|
||||
If `verbose` is an integer, the evaluation metric is printed at each
|
||||
`verbose` boosting stage. The last boosting stage / the boosting stage found
|
||||
by using `early_stopping_rounds` is also printed.
|
||||
xgb_model :
|
||||
file name of stored XGBoost model or 'Booster' instance XGBoost model to be
|
||||
loaded before training (allows training continuation).
|
||||
@@ -1117,7 +1115,6 @@ class XGBModel(XGBModelBase):
|
||||
self,
|
||||
X: ArrayLike,
|
||||
output_margin: bool = False,
|
||||
ntree_limit: Optional[int] = None,
|
||||
validate_features: bool = True,
|
||||
base_margin: Optional[ArrayLike] = None,
|
||||
iteration_range: Optional[Tuple[int, int]] = None,
|
||||
@@ -1135,8 +1132,6 @@ class XGBModel(XGBModelBase):
|
||||
Data to predict with.
|
||||
output_margin :
|
||||
Whether to output the raw untransformed margin value.
|
||||
ntree_limit :
|
||||
Deprecated, use `iteration_range` instead.
|
||||
validate_features :
|
||||
When this is True, validate that the Booster's and data's feature_names are
|
||||
identical. Otherwise, it is assumed that the feature_names are the same.
|
||||
@@ -1156,9 +1151,6 @@ class XGBModel(XGBModelBase):
|
||||
|
||||
"""
|
||||
with config_context(verbosity=self.verbosity):
|
||||
iteration_range = _convert_ntree_limit(
|
||||
self.get_booster(), ntree_limit, iteration_range
|
||||
)
|
||||
iteration_range = self._get_iteration_range(iteration_range)
|
||||
if self._can_use_inplace_predict():
|
||||
try:
|
||||
@@ -1197,7 +1189,6 @@ class XGBModel(XGBModelBase):
|
||||
def apply(
|
||||
self,
|
||||
X: ArrayLike,
|
||||
ntree_limit: int = 0,
|
||||
iteration_range: Optional[Tuple[int, int]] = None,
|
||||
) -> np.ndarray:
|
||||
"""Return the predicted leaf every tree for each sample. If the model is trained
|
||||
@@ -1211,9 +1202,6 @@ class XGBModel(XGBModelBase):
|
||||
iteration_range :
|
||||
See :py:meth:`predict`.
|
||||
|
||||
ntree_limit :
|
||||
Deprecated, use ``iteration_range`` instead.
|
||||
|
||||
Returns
|
||||
-------
|
||||
X_leaves : array_like, shape=[n_samples, n_trees]
|
||||
@@ -1223,9 +1211,6 @@ class XGBModel(XGBModelBase):
|
||||
|
||||
"""
|
||||
with config_context(verbosity=self.verbosity):
|
||||
iteration_range = _convert_ntree_limit(
|
||||
self.get_booster(), ntree_limit, iteration_range
|
||||
)
|
||||
iteration_range = self._get_iteration_range(iteration_range)
|
||||
test_dmatrix = DMatrix(
|
||||
X,
|
||||
@@ -1309,10 +1294,6 @@ class XGBModel(XGBModelBase):
|
||||
"""
|
||||
return int(self._early_stopping_attr("best_iteration"))
|
||||
|
||||
@property
|
||||
def best_ntree_limit(self) -> int:
|
||||
return int(self._early_stopping_attr("best_ntree_limit"))
|
||||
|
||||
@property
|
||||
def feature_importances_(self) -> np.ndarray:
|
||||
"""Feature importances property, return depends on `importance_type`
|
||||
@@ -1562,7 +1543,6 @@ class XGBClassifier(XGBModel, XGBClassifierMixIn, XGBClassifierBase):
|
||||
self,
|
||||
X: ArrayLike,
|
||||
output_margin: bool = False,
|
||||
ntree_limit: Optional[int] = None,
|
||||
validate_features: bool = True,
|
||||
base_margin: Optional[ArrayLike] = None,
|
||||
iteration_range: Optional[Tuple[int, int]] = None,
|
||||
@@ -1571,7 +1551,6 @@ class XGBClassifier(XGBModel, XGBClassifierMixIn, XGBClassifierBase):
|
||||
class_probs = super().predict(
|
||||
X=X,
|
||||
output_margin=output_margin,
|
||||
ntree_limit=ntree_limit,
|
||||
validate_features=validate_features,
|
||||
base_margin=base_margin,
|
||||
iteration_range=iteration_range,
|
||||
@@ -1599,7 +1578,6 @@ class XGBClassifier(XGBModel, XGBClassifierMixIn, XGBClassifierBase):
|
||||
def predict_proba(
|
||||
self,
|
||||
X: ArrayLike,
|
||||
ntree_limit: Optional[int] = None,
|
||||
validate_features: bool = True,
|
||||
base_margin: Optional[ArrayLike] = None,
|
||||
iteration_range: Optional[Tuple[int, int]] = None,
|
||||
@@ -1612,14 +1590,12 @@ class XGBClassifier(XGBModel, XGBClassifierMixIn, XGBClassifierBase):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
X : array_like
|
||||
X :
|
||||
Feature matrix. See :ref:`py-data` for a list of supported types.
|
||||
ntree_limit : int
|
||||
Deprecated, use `iteration_range` instead.
|
||||
validate_features : bool
|
||||
validate_features :
|
||||
When this is True, validate that the Booster's and data's feature_names are
|
||||
identical. Otherwise, it is assumed that the feature_names are the same.
|
||||
base_margin : array_like
|
||||
base_margin :
|
||||
Margin added to prediction.
|
||||
iteration_range :
|
||||
Specifies which layer of trees are used in prediction. For example, if a
|
||||
@@ -1642,7 +1618,6 @@ class XGBClassifier(XGBModel, XGBClassifierMixIn, XGBClassifierBase):
|
||||
if self.objective == "multi:softmax":
|
||||
raw_predt = super().predict(
|
||||
X=X,
|
||||
ntree_limit=ntree_limit,
|
||||
validate_features=validate_features,
|
||||
base_margin=base_margin,
|
||||
iteration_range=iteration_range,
|
||||
@@ -1652,7 +1627,6 @@ class XGBClassifier(XGBModel, XGBClassifierMixIn, XGBClassifierBase):
|
||||
return class_prob
|
||||
class_probs = super().predict(
|
||||
X=X,
|
||||
ntree_limit=ntree_limit,
|
||||
validate_features=validate_features,
|
||||
base_margin=base_margin,
|
||||
iteration_range=iteration_range,
|
||||
@@ -1990,9 +1964,9 @@ class XGBRanker(XGBModel, XGBRankerMixIn):
|
||||
verbose :
|
||||
If `verbose` is True and an evaluation set is used, the evaluation metric
|
||||
measured on the validation set is printed to stdout at each boosting stage.
|
||||
If `verbose` is an integer, the evaluation metric is printed at each `verbose`
|
||||
boosting stage. The last boosting stage / the boosting stage found by using
|
||||
`early_stopping_rounds` is also printed.
|
||||
If `verbose` is an integer, the evaluation metric is printed at each
|
||||
`verbose` boosting stage. The last boosting stage / the boosting stage found
|
||||
by using `early_stopping_rounds` is also printed.
|
||||
xgb_model :
|
||||
file name of stored XGBoost model or 'Booster' instance XGBoost model to be
|
||||
loaded before training (allows training continuation).
|
||||
@@ -2074,7 +2048,6 @@ class XGBRanker(XGBModel, XGBRankerMixIn):
|
||||
self,
|
||||
X: ArrayLike,
|
||||
output_margin: bool = False,
|
||||
ntree_limit: Optional[int] = None,
|
||||
validate_features: bool = True,
|
||||
base_margin: Optional[ArrayLike] = None,
|
||||
iteration_range: Optional[Tuple[int, int]] = None,
|
||||
@@ -2083,20 +2056,18 @@ class XGBRanker(XGBModel, XGBRankerMixIn):
|
||||
return super().predict(
|
||||
X,
|
||||
output_margin,
|
||||
ntree_limit,
|
||||
validate_features,
|
||||
base_margin,
|
||||
iteration_range,
|
||||
iteration_range=iteration_range,
|
||||
)
|
||||
|
||||
def apply(
|
||||
self,
|
||||
X: ArrayLike,
|
||||
ntree_limit: int = 0,
|
||||
iteration_range: Optional[Tuple[int, int]] = None,
|
||||
) -> ArrayLike:
|
||||
X, _ = _get_qid(X, None)
|
||||
return super().apply(X, ntree_limit, iteration_range)
|
||||
return super().apply(X, iteration_range)
|
||||
|
||||
def score(self, X: ArrayLike, y: ArrayLike) -> float:
|
||||
"""Evaluate score for data using the last evaluation metric. If the model is
|
||||
|
||||
@@ -11,7 +11,6 @@ from xgboost import DataIter, DMatrix, QuantileDMatrix, XGBModel
|
||||
from xgboost.compat import concat
|
||||
|
||||
from .._typing import ArrayLike
|
||||
from ..core import _convert_ntree_limit
|
||||
from .utils import get_logger # type: ignore
|
||||
|
||||
|
||||
@@ -343,8 +342,7 @@ def pred_contribs(
|
||||
strict_shape: bool = False,
|
||||
) -> np.ndarray:
|
||||
"""Predict contributions with data with the full model."""
|
||||
iteration_range = _convert_ntree_limit(model.get_booster(), None, None)
|
||||
iteration_range = model._get_iteration_range(iteration_range)
|
||||
iteration_range = model._get_iteration_range(None)
|
||||
data_dmatrix = DMatrix(
|
||||
data,
|
||||
base_margin=base_margin,
|
||||
|
||||
@@ -95,7 +95,7 @@ def train(
|
||||
feval :
|
||||
.. deprecated:: 1.6.0
|
||||
Use `custom_metric` instead.
|
||||
maximize : bool
|
||||
maximize :
|
||||
Whether to maximize feval.
|
||||
early_stopping_rounds :
|
||||
Activates early stopping. Validation metric needs to improve at least once in
|
||||
|
||||
Reference in New Issue
Block a user