skfolio.containers.FieldCategorical#
- class skfolio.containers.FieldCategorical(values, levels, *, inactive_policy=MISSING)[source]#
Integer-coded categorical 2D field.
Codes are stored as integers in a 2D array with axes (observations, assets). Code -1 is reserved for missing values. Code 0 selects
levels[0], code 1 selectslevels[1]and so on.- Parameters:
- valuesintegers ndarray of shape (n_observations, n_assets)
Integer category codes. Missing values must be encoded with
MISSING_CATEGORY_CODE.- levelsndarray of shape (n_levels,)
Category labels selected by codes 0, 1 and so on. Labels must be unique.
- Attributes:
dtypeDtype of the underlying values.
- inactive_policy
is_3dWhether or not the field is a 3D field.
is_categoricalWhether or not the field is a categorical field.
- levels
missing_maskReturn a boolean mask indicating missing categorical codes.
n_assetsNumber of assets.
n_observationsNumber of observations.
ndimNumber of dimensions of the underlying values.
shapeShape of the underlying values.
- values
Methods
copy(*[, deep])Return a copy of the field.
decode(*[, missing_label])Decode integer codes to level labels.
with_values(values)Return a field of the same type with replacement values.
- copy(*, deep=False)#
Return a copy of the field.
- Parameters:
- deepbool, default=False
If
True, copy NumPy arrays stored by the field. IfFalse, reuse the same array objects.
- Returns:
- fieldBaseField
Field instance of the same concrete class.
- decode(*, missing_label='MISSING')[source]#
Decode integer codes to level labels.
- Parameters:
- missing_labelstr, default=”MISSING”
Label assigned to missing or out-of-bound codes.
- Returns:
- decodedndarray
Decoded labels with the same shape as
values.
- property dtype#
Dtype of the underlying values.
- property is_3d#
Whether or not the field is a 3D field.
- property is_categorical#
Whether or not the field is a categorical field.
- property missing_mask#
Return a boolean mask indicating missing categorical codes.
- Returns:
- maskndarray of bool
Boolean array with the same shape as
values. Entries areTruewherevaluesequalsMISSING_CATEGORY_CODE.
- property n_assets#
Number of assets.
- property n_observations#
Number of observations.
- property ndim#
Number of dimensions of the underlying values.
- property shape#
Shape of the underlying values.
- with_values(values)#
Return a field of the same type with replacement values.
Metadata arrays are reused. The replacement values are validated by the concrete field class constructor.
- Parameters:
- valuesarray-like
Replacement field values.
- Returns:
- fieldBaseField
Field instance of the same concrete class.