cursus.steps.scripts.temporal_feature_engineering

Temporal Feature Engineering Script

This script extracts comprehensive temporal features from normalized sequence data, combining generic temporal features with time window aggregations. Designed to consume the output from temporal_sequence_normalization and produce rich temporal features for machine learning models.

Supports configurable feature types, time windows, and processing strategies.

load_normalized_sequences(input_dir, input_format='numpy', logger=None)[source]

Load normalized sequences from TemporalSequenceNormalization output.

Parameters:
  • input_dir (str) – Path to normalized sequences directory

  • input_format (str) – Format of input data (“numpy”, “parquet”, “csv”)

  • logger (Callable | None) – Optional logger function

Returns:

  • “categorical”: Categorical sequence arrays

  • ”numerical”: Numerical sequence arrays

  • ”categorical_attention_mask”: Attention masks for categorical data

  • ”numerical_attention_mask”: Attention masks for numerical data

  • ”metadata”: Loaded metadata dictionary

Return type:

Dictionary containing

validate_input_data(normalized_data, logger=None)[source]

Validate the structure of normalized sequence data.

class GenericTemporalFeaturesOperation(config, logger=None)[source]

Bases: object

Extracts generic temporal features from normalized sequences.

Extracted from TSA feature engineering requirements and general temporal modeling needs.

process(normalized_data)[source]

Extract generic temporal features from normalized sequences.

Parameters:

normalized_data (Dict[str, ndarray]) – Dictionary containing normalized sequence data

Returns:

Dictionary with extracted temporal features

Return type:

Dict[str, ndarray]

class TimeWindowAggregationsOperation(config, logger=None)[source]

Bases: object

Computes time window aggregations for multi-scale temporal analysis.

Extracted from TSA time window feature requirements and temporal modeling needs.

process(normalized_data)[source]

Compute time window aggregations for sequences.

Parameters:

normalized_data (Dict[str, ndarray]) – Dictionary containing normalized sequence data

Returns:

Dictionary with computed window aggregation features

Return type:

Dict[str, ndarray]

class FeatureQualityController(config, logger=None)[source]

Bases: object

Comprehensive feature quality control and validation framework.

Ensures engineered features meet quality standards for model consumption.

validate_features(features, feature_names)[source]

Comprehensive feature validation and quality assessment.

Parameters:
  • features (ndarray) – Feature matrix (N_entities, N_features)

  • feature_names (List[str]) – List of feature names

Returns:

Quality report with validation results and recommendations

Return type:

Dict[str, Any]

save_temporal_feature_tensors(feature_tensors, output_dir, output_format='numpy', logger=None)[source]

Save temporal feature tensors in the specified format.

main(input_paths, output_paths, environ_vars, job_args, logger=None)[source]

Main logic for temporal feature engineering.

Parameters:
  • input_paths (Dict[str, str]) – Dictionary of input paths with logical names

  • output_paths (Dict[str, str]) – Dictionary of output paths with logical names

  • environ_vars (Dict[str, str]) – Dictionary of environment variables

  • job_args (Namespace) – Command line arguments

  • logger (Callable[[str], None] | None) – Optional logger object (defaults to print if None)

Returns:

Dictionary of temporal feature tensors

Return type:

Dict[str, ndarray]