regressioninc.validation module#
A module with functions for checking and validating arrays
- regressioninc.validation.num_samples(x: ndarray) int[source]#
Get the numbers of samples in an array
- Parameters:
x (np.ndarray) – The array for which to calculate the number of samples
- Returns:
The number of samples
- Return type:
int
- regressioninc.validation.validate_non_negative(x: ndarray)[source]#
Validate that an array has no negative values
- Parameters:
x (np.ndarray) – The array to check
- Raises:
ValueError – If the array has negative values
Examples
>>> import numpy as np >>> from regressioninc.validation import validate_non_negative >>> test = np.array([1,2,3,-4]) >>> validate_non_negative(test) Traceback (most recent call last): ... ValueError: Negative values are not allowed
>>> test[3] = 4 >>> validate_non_negative(test)
- regressioninc.validation.validate_lengths(*arrays: ndarray) None[source]#
Check whether arrays have consistent length
- Parameters:
*arrays (np.ndarray) – The arguments which should all be numpy arrays whose lengths will be checked for consistency
- Raises:
ValueError – If the arrays have inconsistent lengths
Examples
>>> import numpy as np >>> from regressioninc.validation import validate_lengths >>> test1 = np.array([1,2,3,4,5]) >>> test2 = np.array([6,7,8,9,10]) >>> test3 = np.array([11,12,13]) >>> validate_lengths(test1, test2) >>> validate_lengths(test1, test3) Traceback (most recent call last): ... ValueError: Row counts [5, 3] are not consistent