Skip to content

Feature Config

Module for handling configuration for feature generation.

Config

A configuration object that defines the dataset and features to be used in a feature generator.

Parameters:

Name Type Description Default
dataset DatasetConfig

The configuration for the dataset to be used.

required
features Sequence[FeatureConfig]

The configurations for the features to be generated.

required

Methods:

Name Description
from_yaml

Load a Config object from a YAML file.

Source code in amee_utils/feature_generator/config.py
@attrs.define
class Config:
    """
    A configuration object that defines the dataset and features to be used in a feature generator.

    Parameters
    ----------
    dataset : DatasetConfig
        The configuration for the dataset to be used.
    features : Sequence[FeatureConfig]
        The configurations for the features to be generated.

    Methods
    -------
    from_yaml(cls, path)
        Load a Config object from a YAML file.

    """

    dataset: DatasetConfig
    features: Sequence[FeatureConfig]

    @classmethod
    def from_yaml(cls, path: Path) -> Config:
        """
        Load a Config object from a YAML file.

        Parameters
        ----------
        path : Path
            The path to the YAML file.

        Returns
        -------
        Config
            The Config object loaded from the YAML file.

        """
        with open(path, "r") as f:
            config = yaml.safe_load(f)

        feature_configs = []
        for feature_class_name, feature_config in config["features"].items():
            feature_config_class: FeatureConfig = getattr(FEATURE_SET_MODULE, feature_class_name)
            if feature_config_class is not None:
                feature_configs.append(feature_config_class(**feature_config))  # type: ignore

        return cls(
            dataset=DatasetConfig(**config["dataset"]),
            features=feature_configs,  # type: ignore
        )

from_yaml(path) classmethod

Load a Config object from a YAML file.

Parameters:

Name Type Description Default
path Path

The path to the YAML file.

required

Returns:

Type Description
Config

The Config object loaded from the YAML file.

Source code in amee_utils/feature_generator/config.py
@classmethod
def from_yaml(cls, path: Path) -> Config:
    """
    Load a Config object from a YAML file.

    Parameters
    ----------
    path : Path
        The path to the YAML file.

    Returns
    -------
    Config
        The Config object loaded from the YAML file.

    """
    with open(path, "r") as f:
        config = yaml.safe_load(f)

    feature_configs = []
    for feature_class_name, feature_config in config["features"].items():
        feature_config_class: FeatureConfig = getattr(FEATURE_SET_MODULE, feature_class_name)
        if feature_config_class is not None:
            feature_configs.append(feature_config_class(**feature_config))  # type: ignore

    return cls(
        dataset=DatasetConfig(**config["dataset"]),
        features=feature_configs,  # type: ignore
    )

DatasetConfig

Configuration for a dataset.

Attributes:

Name Type Description
key_cols list[str]

List of column names that serve as keys for the dataset.

date_col str

Name of the column that contains date information for the dataset.

Source code in amee_utils/feature_generator/config.py
@attrs.define
class DatasetConfig:
    """
    Configuration for a dataset.

    Attributes
    ----------
    key_cols : list[str]
        List of column names that serve as keys for the dataset.
    date_col : str
        Name of the column that contains date information for the dataset.
    """

    key_cols: list[str]
    date_col: str

FeatureConfig

A generic configuration class for features.

Source code in amee_utils/feature_generator/config.py
@attrs.define
class FeatureConfig:
    """A generic configuration class for features."""

    def get_function_dict(self) -> dict:
        """Return a dictionary of feature functions and their corresponding column names.

        Returns
        -------
        dict
            A dictionary of feature functions and their corresponding column names.

        """
        raise NotImplementedError

get_function_dict()

Return a dictionary of feature functions and their corresponding column names.

Returns:

Type Description
dict

A dictionary of feature functions and their corresponding column names.

Source code in amee_utils/feature_generator/config.py
def get_function_dict(self) -> dict:
    """Return a dictionary of feature functions and their corresponding column names.

    Returns
    -------
    dict
        A dictionary of feature functions and their corresponding column names.

    """
    raise NotImplementedError