Use config_context in sklearn interface. (#8141)
This commit is contained in:
@@ -70,6 +70,23 @@ def config_doc(
|
||||
# Suppress warning caused by model generated with XGBoost version < 1.0.0
|
||||
bst = xgb.Booster(model_file='./old_model.bin')
|
||||
assert xgb.get_config()['verbosity'] == 2 # old value restored
|
||||
|
||||
Nested configuration context is also supported:
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
with xgb.config_context(verbosity=3):
|
||||
assert xgb.get_config()["verbosity"] == 3
|
||||
with xgb.config_context(verbosity=2):
|
||||
assert xgb.get_config()["verbosity"] == 2
|
||||
|
||||
xgb.set_config(verbosity=2)
|
||||
assert xgb.get_config()["verbosity"] == 2
|
||||
with xgb.config_context(verbosity=3):
|
||||
assert xgb.get_config()["verbosity"] == 3
|
||||
"""
|
||||
|
||||
def none_to_str(value: Optional[str]) -> str:
|
||||
@@ -98,7 +115,11 @@ def config_doc(
|
||||
Keyword arguments representing the parameters and their values
|
||||
""")
|
||||
def set_config(**new_config: Any) -> None:
|
||||
config = json.dumps(new_config)
|
||||
not_none = {}
|
||||
for k, v in new_config.items():
|
||||
if v is not None:
|
||||
not_none[k] = v
|
||||
config = json.dumps(not_none)
|
||||
_check_call(_LIB.XGBSetGlobalConfig(c_str(config)))
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user