Validate scalar parameters type and value.
The scalar parameter to validate.
The name of the parameter to be printed in error messages.
Acceptable data types for the parameter.
The minimum valid value the parameter can take. If None (default) it is implied that the parameter does not have a lower bound.
The maximum valid value the parameter can take. If None (default) it is implied that the parameter does not have an upper bound.
Whether the interval defined by min_val and max_val should include the boundaries. Possible choices are:
"left": only min_val is included in the valid interval. It is equivalent to the interval [ min_val, max_val )."right": only max_val is included in the valid interval. It is equivalent to the interval ( min_val, max_val ]."both": min_val and max_val are included in the valid interval. It is equivalent to the interval [ min_val, max_val ]."neither": neither min_val nor max_val are included in the valid interval. It is equivalent to the interval ( min_val, max_val ).The validated number.
If the parameter’s type does not match the desired type.
If the parameter’s value violates the given bounds. If min_val, max_val and include_boundaries are inconsistent.
>>> from sklearn.utils.validation import check_scalar >>> check_scalar(10, "x", int, min_val=1, max_val=20) 10
© 2007–2025 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.6/modules/generated/sklearn.utils.check_scalar.html