Skip to main content
Version: 0.5.x

module

Contains functions responsible for validating data types.

Module: aisp.utils.validation
Import: from aisp.utils import validation

Functions

detect_vector_data_type

def detect_vector_data_type(vector: npt.NDArray) -> FeatureType:
...

Detect the type of data in a vector.

The function detects if the vector contains data of type:

  • Binary features: boolean values or integers restricted to 0 and 1.
  • Continuous features: floating-point values in the normalized range [0.0, 1.0].
  • Ranged features: floating-point values outside the normalized range.

Parameters

NameTypeDefaultDescription
vectornpt.NDArray-An array containing the data to be classified.

Returns

TypeDescription
FeatureTypeThe data type of the vector: "binary-features", "continuous-features", or " ranged-features".

Raises

ExceptionDescription
UnsupportedTypeErrorIf the data type of the vector is not supported by the function.

check_array_type

def check_array_type(x, name: str = "X") -> npt.NDArray:
...

Ensure X is a numpy array. Convert from list if needed.

Parameters

NameTypeDefaultDescription
xAny-Array, containing the samples and their characteristics, Shape: (n_samples, n_features).
namestr'X'Variable name used in error messages.

Returns

TypeDescription
npt.NDArrayThe converted or validated array

Raises

ExceptionDescription
TypeErrorIf X is not ndarray or a list.

check_shape_match

def check_shape_match(x: npt.NDArray, y: npt.NDArray):
...

Ensure X and y have compatible first dimensions.

Parameters

NameTypeDefaultDescription
xnpt.NDArray-Array, containing the samples and their characteristics, Shape: (n_samples, n_features).
ynpt.NDArray-Array of target classes of x with (n_samples).

Raises

ExceptionDescription
TypeErrorIf x or y have incompatible shapes.

check_feature_dimension

def check_feature_dimension(x: npt.NDArray, expected: int):
...

Ensure X has the expected number of features.

Parameters

NameTypeDefaultDescription
xnpt.NDArray-Input array for prediction, containing the samples and their characteristics, Shape: (n_samples, n_features).
expectedint-Expected number of features per sample (columns in X).

Raises

ExceptionDescription
FeatureDimensionMismatchIf the number of features in X does not match the expected number.

check_binary_array

def check_binary_array(x: npt.NDArray):
...

Ensure X contains only 0 and 1.

Parameters

NameTypeDefaultDescription
xnpt.NDArray-Array, containing the samples.

Raises

ExceptionDescription
ValueErrorIf the array contains values other than 0 and 1.

check_value_range

def check_value_range(
x: npt.NDArray,
name: str = 'X',
min_value: float = 0.0,
max_value: float = 1.0
) -> None:
...

Ensure all values in the x array fall within a range.

Parameters

NameTypeDefaultDescription
xnpt.NDArray-Array, containing the samples.
namestr'X'Name used in the error message.
min_valuefloat0.0Minimum allowed value.
max_valuefloat1.0Maximum allowed value.

Raises

ExceptionDescription
ValueErrorIf the array fall outside the interval (min_value, max_value).