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_array(x: ndarray)[source]#

Perform various checks on array

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
regressioninc.validation.validate_X_y(X: ndarray, y: ndarray) Tuple[ndarray, ndarray][source]#

Run a series of checks for X and y

regressioninc.validation.validate_weights(weights, X, non_negative=True)[source]#

Validate weights