sklearn.utils.check_scalar

sklearn.utils.check_scalar(x, name, target_type, min_val=None, max_val=None)[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, optional (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, optional (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.

Raises
TypeError

If the parameter’s type does not match the desired type.

ValueError

If the parameter’s value violates the given bounds.