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:
x : object

The scalar parameter to validate.

name : str

The name of the parameter to be printed in error messages.

target_type : type or tuple

Acceptable data types for the parameter.

min_val : float 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_val : float 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.