Features

The AutoCarver.features module defines a set of features used in the AutoCarver project. This module includes classes and functions to handle different types of features, such as qualitative and quantitative features.

Features

class AutoCarver.features.Features(categoricals: list[str] | None = None, quantitatives: list[str] | None = None, ordinals: dict[str, list[str]] | None = None, config: FeaturesConfig | None = None)

A set of typed features

Build a Features collection from column names.

Parameters:
  • categoricals (list[str], optional) – Categorical column names, by default None.

  • quantitatives (list[str], optional) – Quantitative column names, by default None.

  • ordinals (dict[str, list[str]], optional) – Ordinal column names mapped to their ordered value list, by default None.

  • config (FeaturesConfig, optional) – Collection-level config propagated to each feature, by default None.

Warning

At least one of categoricals, quantitatives or ordinals must be provided. To build a Features from already-instantiated feature objects, use Features.from_list() instead.

property categoricals: list[CategoricalFeature]

Returns all categorical features

classmethod from_list(features: Iterable[BaseFeature] | Features, config: FeaturesConfig | None = None) Features

Build a Features from already-instantiated feature objects.

Parameters:
  • features (Iterable[BaseFeature] | Features) – Feature instances to wrap. Iterating an existing Features is supported.

  • config (FeaturesConfig, optional) – Collection-level config propagated to each feature, by default None.

property history: DataFrame

Combined history of all features (concatenated, with a feature column).

classmethod load(features_json: dict) Features

Allows one to load a set of Features

Parameters:

features_json (dict) – Dictionary of serialized Features

Returns:

Loaded Features.

Return type:

Features

property names: list[str]

Returns names of all features

property ordinals: list[OrdinalFeature]

Returns all ordinal features

property qualitatives: list[OrdinalFeature | CategoricalFeature]

Returns all qualitative features

property quantitatives: list[QuantitativeFeature]

Returns all quantitative features

property summary: DataFrame

Summary of discretization process for all features

to_json(light_mode: bool = False) dict

Serializes Features for JSON saving

Parameters:

light_mode (bool, optional) – Whether or not to serialize in light mode (without statistics and history), by default False

property versions: list[str]

Returns versions of all features

Note

Use the default constructor when you only have column names; use Features.from_list() to wrap already-instantiated feature objects.

FeaturesConfig

Collection-level state propagated to every feature in a Features. Internal feature attributes (nan, default, ordinal_encoding, has_nan, has_default, dropna, is_fitted) are not part of the public BaseFeature constructor — set them via FeaturesConfig and pass the instance to Features or Features.from_list().

class AutoCarver.features.FeaturesConfig(nan: str | None = None, default: str | None = None, ordinal_encoding: bool = False, is_fitted: bool = False, has_nan: bool = False, has_default: bool = False, dropna: bool = False)

Collection-level config applied to each feature in a Features.

Internal feature state (nan/default/ordinal_encoding/…) is not part of the public BaseFeature constructor — pass them via this dataclass to Features or Features.from_list and they are propagated to each constituent feature.

Qualitatitve features

class AutoCarver.features.CategoricalFeature(name: str, *, max_n_chars: int = 50)

Defines a categorical feature

property has_default: bool

Whether the feature has default values.

property history: DataFrame

Combination history as a DataFrame (empty when no history yet).

Stored internally as a list of dicts in _history for JSON serialization; the DataFrame is rebuilt on access. Append entries with historize().

property summary: list[dict]

Summary of feature’s discretization process.

class AutoCarver.features.OrdinalFeature(name: str, values: list[str])

Defines an ordinal feature

Parameters:

values (list[str]) – Ordered list of all unique values for the feature

property has_default: bool

Whether the feature has default values.

property history: DataFrame

Combination history as a DataFrame (empty when no history yet).

Stored internally as a list of dicts in _history for JSON serialization; the DataFrame is rebuilt on access. Append entries with historize().

property summary: list[dict]

Summary of feature’s discretization process.

Quantitative features

class AutoCarver.features.QuantitativeFeature(name: str)

Defines a quantitative feature

property has_default: bool

Whether the feature has default values.

property history: DataFrame

Combination history as a DataFrame (empty when no history yet).

Stored internally as a list of dicts in _history for JSON serialization; the DataFrame is rebuilt on access. Append entries with historize().

property summary: list[dict]

Summary of feature’s discretization process.