lir.transform.data_validator module

class lir.transform.data_validator.ValidateFeatureDataType[source]

Bases: Transformer

Module that validates the data types of the features in the instances.

This transformer is useful for ensuring that the data types of the features in the instances are consistent with the data types determined during fitting. This can help prevent errors during the application of a model/pipeline. Especially useful when the model or the applied data is read from file.

In short, it checks: 1. That the number of features in the instances matches the number of data types determined during fitting. 2. That the data types of the features can be cast to the data types determined during fitting.

apply(instances: InstanceData) FeatureData[source]

Apply the transformer to the data by enforcing the data types of each feature.

Will raise an error if the data types of the features in the instances do not match the data types determined during fitting.

Parameters:

instances (InstanceData) – The data to apply the transformer on.

Returns:

The transformed data with validated data types.

Return type:

FeatureData

Raises:
  • ValueError – If the number of features in the instances does not match the number of data types determined during fitting

  • TypeError – If the data types of the features in the instances cannot be cast to the data type determined during fitting

fit(instances: InstanceData) Self[source]

Fit the transformer to the data by determining the data types of each feature in the first instance.

It assumes that all instances have the same data types for each feature.

Parameters:

instances (InstanceData) – The data to fit the transformer on.

Returns:

The fitted transformer.

Return type:

Self