saealib.CategoricalVariable#

class saealib.CategoricalVariable(categories)[ソース]#

ベースクラス: Variable

Categorical variable; stored internally as integer index.

Values are encoded as indices in [0, n_categories - 1] and stored as float64 in population arrays. Use encode() / decode() to convert between category values and their integer indices.

パラメータ:

categories (list) -- Ordered list of category values. Must be non-empty.

サンプル

>>> v = CategoricalVariable(["red", "green", "blue"])
>>> v.encode("green")
1
>>> v.decode(1)
'green'

Methods

__init__

decode

Return the category value for index.

encode

Return the integer index for category.

repair

Round x and clip to a valid category index.

Method Details

CategoricalVariable.__init__(categories)[ソース]#
パラメータ:

categories (list)

戻り値の型:

None

CategoricalVariable.decode(index)[ソース]#

Return the category value for index.

パラメータ:

index (int or float) -- Index into categories; rounded to nearest integer.

戻り値の型:

category value

CategoricalVariable.encode(category)[ソース]#

Return the integer index for category.

パラメータ:

category -- A value present in categories.

戻り値の型:

int

CategoricalVariable.repair(x)[ソース]#

Round x and clip to a valid category index.

パラメータ:

x (np.ndarray) -- Values for this dimension.

戻り値:

Rounded and clipped values in [0, n_categories - 1].

戻り値の型:

np.ndarray