Skip to content

feature

The features module provides a list of feature object to be used to define the dataset structure.

Modules:

Name Description
abstracts

Feature abstract classes module.

augmentation

feature's utils.

feature

Represent a feature object.

feature_types

Feature types module.

Classes:

Name Description
BaseFeature

Base Feature used if no convenient available feature.

ExplainableFeature

Define a feature object.

IndexMetadata

Represents an index metadata, automatically added to the schema, cf doc dataset/concept.

FeatureConvertor

Class for converting exposed features into feature.

BaseFeature #

Base Feature used if no convenient available feature.

Methods:

Name Description
from_exposed

BaseFeature from ExposedBaseFeature.

as_exposed

BaseFeature as ExposedBaseFeature.

from_exposed(exposed_feature: ExposedBaseFeature) -> BaseFeature #

BaseFeature from ExposedBaseFeature.

Source code in src/xpdeep/dataset/feature/feature.py
@staticmethod
def from_exposed(exposed_feature: ExposedBaseFeature) -> "BaseFeature":
    """BaseFeature from ExposedBaseFeature."""
    return BaseFeature(**msgspec_asdict(exposed_feature))

as_exposed() -> ExposedBaseFeature #

BaseFeature as ExposedBaseFeature.

Source code in src/xpdeep/dataset/feature/feature.py
def as_exposed(self) -> ExposedBaseFeature:
    """BaseFeature as ExposedBaseFeature."""
    return ExposedBaseFeature(**_attrs_asdict(self))

ExplainableFeature #

Define a feature object.

Parameters:

Name Type Description Default

id #

UUID | None

Feature Identifier

None

is_target #

bool

Whether the feature is target or not.

False

preprocessor #

TorchPreprocessor | SklearnPreprocessor | IdentityPreprocessor

The feature preprocessor function used to preprocess the data.

required

feature_augmentation #

ImageFeatureAugmentation | None

Feature augmentation functions, currently supported: ImageFeatureAugmentation.

None

Methods:

Name Description
from_exposed

Convert exposed feature to feature as dict.

as_exposed

Explainable Feature as ExposedFeatureWithPreprocessor.

Attributes:

Name Type Description
preprocessor TorchPreprocessor | SklearnPreprocessor | IdentityPreprocessor
feature_augmentation ImageFeatureAugmentation | None

preprocessor: TorchPreprocessor | SklearnPreprocessor | IdentityPreprocessor = field(kw_only=True) #

feature_augmentation: ImageFeatureAugmentation | None = field(kw_only=True, default=None) #

from_exposed(exposed_feature: ExposedFeatureWithPreprocessor) -> ExplainableFeature #

Convert exposed feature to feature as dict.

Source code in src/xpdeep/dataset/feature/feature.py
@staticmethod
def from_exposed(exposed_feature: ExposedFeatureWithPreprocessor) -> "ExplainableFeature":
    """Convert exposed feature to feature as dict."""
    exposed_feature_as_dict = msgspec_asdict(exposed_feature)

    preprocessor = exposed_feature_as_dict["preprocessor"]

    match preprocessor:
        case ExposedNumpyPreprocessor():
            exposed_feature_as_dict["preprocessor"] = SklearnPreprocessor.from_exposed(preprocessor)
        case ExposedIdentityPreprocessor():
            exposed_feature_as_dict["preprocessor"] = IdentityPreprocessor.from_exposed(preprocessor)
        case ExposedTorchPreprocessor():
            exposed_feature_as_dict["preprocessor"] = TorchPreprocessor.from_exposed(preprocessor)
        case _:
            msg = "Unknown type of preprocessor of the given exposed feature."
            raise NotImplementedError(msg)

    exposed_feature_as_dict["feature_type"] = FeatureTypeConvertor.from_exposed(
        exposed_feature_as_dict["feature_type"]
    )

    return ExplainableFeature(**exposed_feature_as_dict)

as_exposed(*, with_augmentation: bool) -> ExposedFeatureWithPreprocessor | ExposedFeatureWithAugmentation #

as_exposed(
    *, with_augmentation: Literal[False]
) -> ExposedFeatureWithPreprocessor
as_exposed(
    *, with_augmentation: Literal[True]
) -> ExposedFeatureWithAugmentation
as_exposed(
    *, with_augmentation: bool
) -> (
    ExposedFeatureWithPreprocessor
    | ExposedFeatureWithAugmentation
)

Explainable Feature as ExposedFeatureWithPreprocessor.

Source code in src/xpdeep/dataset/feature/feature.py
def as_exposed(self, *, with_augmentation: bool) -> ExposedFeatureWithPreprocessor | ExposedFeatureWithAugmentation:
    """Explainable Feature as ExposedFeatureWithPreprocessor."""
    feature_as_dict = {
        feature_field.name: getattr(self, feature_field.name)
        if "as_exposed" not in dir(getattr(self, feature_field.name))
        else getattr(self, feature_field.name).as_exposed
        for feature_field in fields(type(self))
    }

    del feature_as_dict["feature_augmentation"]

    exposed_feature = ExposedFeatureWithPreprocessor(
        name=self.name,
        is_target=self.is_target,
        feature_type=self.feature_type.as_exposed,
        preprocessor=self.preprocessor.as_exposed,
    )

    if with_augmentation:
        return ExposedFeatureWithAugmentation(
            feature_with_preprocessor=exposed_feature,
            feature_augmentation=self.feature_augmentation.as_exposed()
            if self.feature_augmentation is not None
            else None,
        )

    return exposed_feature

IndexMetadata #

Represents an index metadata, automatically added to the schema, cf doc dataset/concept.

Parameters:

Name Type Description Default

name #

str
required

feature_type #

str
'xpdeep_index'

Methods:

Name Description
as_exposed

Generate the corresponding exposed ExposedIndexMetadata.

from_exposed

Create IndexMetadata from ExposedIndexMetadata.

Attributes:

Name Type Description
name str
feature_type str

name: str #

feature_type: str = 'xpdeep_index' #

as_exposed() -> ExposedIndexMetadata #

Generate the corresponding exposed ExposedIndexMetadata.

Source code in src/xpdeep/dataset/feature/feature.py
def as_exposed(self) -> ExposedIndexMetadata:
    """Generate the corresponding exposed ExposedIndexMetadata."""
    return ExposedIndexMetadata(name=self.name)

from_exposed(exposed_metadata: ExposedIndexMetadata) -> IndexMetadata #

Create IndexMetadata from ExposedIndexMetadata.

Source code in src/xpdeep/dataset/feature/feature.py
@staticmethod
def from_exposed(exposed_metadata: ExposedIndexMetadata) -> "IndexMetadata":
    """Create IndexMetadata from ExposedIndexMetadata."""
    return IndexMetadata(name=exposed_metadata.name)

FeatureConvertor #

Class for converting exposed features into feature.

For instance, it recognizes an ExposedBaseFeature and instantiate corresponding BaseFeature.

Methods:

Name Description
from_exposed

Convert exposed feature into feature.

from_exposed(exposed_feature: ExposedBaseFeature | ExposedFeatureWithPreprocessor | ExposedIndexMetadata) -> BaseFeature | ExplainableFeature | IndexMetadata #

Convert exposed feature into feature.

Source code in src/xpdeep/dataset/feature/feature.py
@staticmethod
def from_exposed(
    exposed_feature: ExposedBaseFeature | ExposedFeatureWithPreprocessor | ExposedIndexMetadata,
) -> BaseFeature | ExplainableFeature | IndexMetadata:
    """Convert exposed feature into feature."""
    match exposed_feature:
        case ExposedFeatureWithPreprocessor():
            return ExplainableFeature.from_exposed(exposed_feature)
        case ExposedBaseFeature():
            return BaseFeature.from_exposed(exposed_feature)
        case ExposedIndexMetadata():
            return IndexMetadata.from_exposed(exposed_feature)