Cleanup booster param types. (#8756)
This commit is contained in:
parent
7b3d473593
commit
c4802bfcd0
@ -25,7 +25,7 @@ DataType = Any
|
|||||||
FeatureInfo = Sequence[str]
|
FeatureInfo = Sequence[str]
|
||||||
FeatureNames = FeatureInfo
|
FeatureNames = FeatureInfo
|
||||||
FeatureTypes = FeatureInfo
|
FeatureTypes = FeatureInfo
|
||||||
BoosterParam = Union[List, Dict] # better be sequence
|
BoosterParam = Union[List, Dict[str, Any]] # better be sequence
|
||||||
|
|
||||||
ArrayLike = Any
|
ArrayLike = Any
|
||||||
PathLike = Union[str, os.PathLike]
|
PathLike = Union[str, os.PathLike]
|
||||||
|
|||||||
@ -1655,27 +1655,18 @@ class Booster:
|
|||||||
|
|
||||||
def _configure_constraints(self, params: BoosterParam) -> BoosterParam:
|
def _configure_constraints(self, params: BoosterParam) -> BoosterParam:
|
||||||
if isinstance(params, dict):
|
if isinstance(params, dict):
|
||||||
value = params.get("monotone_constraints")
|
# we must use list in the internal code as there can be multiple metrics
|
||||||
if value is not None:
|
# with the same parameter name `eval_metric` (same key for dictionary).
|
||||||
params["monotone_constraints"] = self._transform_monotone_constrains(
|
params = list(params.items())
|
||||||
value
|
for idx, param in enumerate(params):
|
||||||
)
|
name, value = param
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
|
|
||||||
value = params.get("interaction_constraints")
|
if name == "monotone_constraints":
|
||||||
if value is not None:
|
params[idx] = (name, self._transform_monotone_constrains(value))
|
||||||
params[
|
elif name == "interaction_constraints":
|
||||||
"interaction_constraints"
|
params[idx] = (name, self._transform_interaction_constraints(value))
|
||||||
] = self._transform_interaction_constraints(value)
|
|
||||||
elif isinstance(params, list):
|
|
||||||
for idx, param in enumerate(params):
|
|
||||||
name, value = param
|
|
||||||
if not value:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if name == "monotone_constraints":
|
|
||||||
params[idx] = (name, self._transform_monotone_constrains(value))
|
|
||||||
elif name == "interaction_constraints":
|
|
||||||
params[idx] = (name, self._transform_interaction_constraints(value))
|
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user