sklearn.utils
.check_scalar¶
- sklearn.utils.check_scalar(x, name, target_type, *, min_val=None, max_val=None, include_boundaries='both')[source]¶
Validate scalar parameters type and value.
- Parameters
- xobject
The scalar parameter to validate.
- namestr
The name of the parameter to be printed in error messages.
- target_typetype or tuple
Acceptable data types for the parameter.
- min_valfloat or int, default=None
The minimum valid value the parameter can take. If None (default) it is implied that the parameter does not have a lower bound.
- max_valfloat or int, default=None
The maximum valid value the parameter can take. If None (default) it is implied that the parameter does not have an upper bound.
- include_boundaries{“left”, “right”, “both”, “neither”}, default=”both”
Whether the interval defined by
min_val
andmax_val
should include the boundaries. Possible choices are:"left"
: onlymin_val
is included in the valid interval;"right"
: onlymax_val
is included in the valid interval;"both"
:min_val
andmax_val
are included in the valid interval;"neither"
: neithermin_val
normax_val
are included in the valid interval.
- Returns
- xnumbers.Number
The validated number.
- Raises
- TypeError
If the parameter’s type does not match the desired type.
- ValueError
If the parameter’s value violates the given bounds.