FeatureSelection#

class openstef_models.utils.feature_selection.FeatureSelection(**data: Any) None[source]

Bases: BaseConfig

Standardized feature selection with include/exclude patterns.

Supports both exact matching and regex pattern matching for feature selection. Features can be specified by inclusion (whitelist) or exclusion (blacklist), or both. When both are specified, inclusion is applied first, then exclusion.

Use FeatureSelection.ALL to select all available features.

Example

>>> from openstef_models.utils.feature_selection import (
...     FeatureSelection,
...     Include,
...     Exclude,
... )
>>>
>>> # Select all features
>>> all_features = FeatureSelection.ALL
>>> all_features.resolve(['a', 'b', 'c'])
['a', 'b', 'c']
>>>
>>> # Include only specific features (exact match)
>>> include_only = Include('a', 'b')
>>> include_only.resolve(['a', 'b', 'c', 'd'])
['a', 'b']
>>>
>>> # Exclude specific features (exact match)
>>> exclude_some = Exclude('b', 'd')
>>> exclude_some.resolve(['a', 'b', 'c', 'd'])
['a', 'c']
>>>
>>> # Regex matching
>>> regex_sel = FeatureSelection(include_regex={r'^b_.*'})
>>> regex_sel.resolve(['b_1', 'b_2', 'c_1'])
['b_1', 'b_2']
>>>
>>> # Combine exact and regex
>>> combined = FeatureSelection(include={'a'}, include_regex={r'^b.*'})
>>> combined.resolve(['a', 'b1', 'b2', 'c'])
['a', 'b1', 'b2']
Parameters:

data (Any)

include: set[str] | None
include_regex: set[str] | None
exclude: set[str] | None
exclude_regex: set[str] | None
ALL: ClassVar[Self] = FeatureSelection(include=None, include_regex=None, exclude=None, exclude_regex=None)
NONE: ClassVar[Self] = FeatureSelection(include=set(), include_regex=set(), exclude=None, exclude_regex=None)
resolve(features: list[str]) list[str][source]

Resolve the final list of features based on include and exclude filters.

Parameters:
  • features (list[str]) – List of all available feature names.

  • features

Returns:

List of feature names after applying include and exclude filters.

Return type:

list[str]

combine(other: Self | None) Self[source]

Create a new FeatureSelection that is the union of this and another.

Parameters:
  • other (Optional[Self]) – Another FeatureSelection instance.

  • other

Returns:

A new FeatureSelection instance that is the union of this and the other instance.

Return type:

Self

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': False, 'extra': 'ignore', 'protected_namespaces': ()}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].