categorical
Categorical and ordinal features.
Classes:
| Name | Description |
|---|---|
CategoricalFeature |
Categorical feature. |
OrdinalFeature |
Feature representing an ordered categorical variable. |
CategoricalFeature
#
Categorical feature.
It represents data (bool, int or str only) that can be divided into distinct groups or categories.
It may be nominal or ordinal. For instance, "Education level" or "gender" could be set as categorical features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[str] | list[int] | None
|
|
None
|
Methods:
| Name | Description |
|---|---|
to_model |
Convert to CategoricalFeatureType instance. |
parse_categories_to_list |
Convert categories to an empty list if they are None. |
__attrs_post_init__ |
Return a fake category to be overwritten by the fitted preprocessor inferred categories. |
from_model |
Instantiate from a json response. |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Literal['CATEGORICAL']
|
|
categories |
list[str] | list[int] | None
|
|
name: Literal['CATEGORICAL'] = 'CATEGORICAL'
#
categories: list[str] | list[int] | None = None
#
to_model() -> CategoricalFeatureType
#
Convert to CategoricalFeatureType instance.
parse_categories_to_list(categories: list[str] | list[int] | None) -> list[str] | list[int]
#
Convert categories to an empty list if they are None.
Source code in src/xpdeep/dataset/feature/feature_types/categorical.py
__attrs_post_init__() -> None
#
Return a fake category to be overwritten by the fitted preprocessor inferred categories.
from_model(feature_type_input: CategoricalFeatureType) -> CategoricalFeature
#
Instantiate from a json response.
Source code in src/xpdeep/dataset/feature/feature_types/categorical.py
OrdinalFeature
#
Feature representing an ordered categorical variable.
An ordinal feature encodes categories that have a defined order or ranking, such as "low", "medium", "high". In contrast to nominal (unordered) categories, ordinal features include a notion of distance between categories, quantified by an associated cost matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[str] or list[int]
|
Ordered list of category labels. The order in the list must correspond to the order used in the cost matrix. |
required |
|
ndarray
|
Two-dimensional matrix specifying the pairwise cost or distance between categories. The entry at position (i, j) represents the cost of moving from category i to category j. |
required |
Methods:
| Name | Description |
|---|---|
to_model |
Convert to an |
from_model |
Instantiate from a json response. |
Attributes:
| Name | Type | Description |
|---|---|---|
categories |
list[str] | list[int]
|
|
cost_matrix |
ndarray
|
|
name |
Literal['ORDINAL']
|
|
categories: list[str] | list[int]
#
cost_matrix: np.ndarray
#
name: Literal['ORDINAL'] = 'ORDINAL'
#
to_model() -> OrdinalFeatureType
#
Convert to an OrdinalFeatureType instance.
Returns:
| Type | Description |
|---|---|
OrdinalFeatureType
|
A feature model representation including the category list and cost matrix. |
Source code in src/xpdeep/dataset/feature/feature_types/categorical.py
from_model(feature_type_input: OrdinalFeatureType) -> OrdinalFeature
#
Instantiate from a json response.