myfm.utils.encoders.CategoryValueToSparseEncoder

class myfm.utils.encoders.CategoryValueToSparseEncoder(items: typing.Iterable[myfm.utils.encoders.categorical.T], min_freq: int = 1, handle_unknown: typing_extensions.Literal[create, ignore, raise] = 'create')[source]

Bases: Generic[myfm.utils.encoders.categorical.T], myfm.utils.encoders.base.SparseEncoderBase

The class to one-hot encode a List of items into a sparse matrix representation.

__init__(items: typing.Iterable[myfm.utils.encoders.categorical.T], min_freq: int = 1, handle_unknown: typing_extensions.Literal[create, ignore, raise] = 'create')[source]

Construct the encoder by providing a list of items.

Parameters
  • items (Iterable[T]) – The items list.

  • min_freq (int, optional) – The minimal frequency for an item to be retained in the known items list, by default 1

  • handle_unknown (Literal["create", "ignore", "raise"], optional) – How to handle previously unseen values during encoding. If “create”, then there is a single category named “__UNK__” for unknown values, ant it is treated as 0th category. If “ignore”, such an item will be ignored. If “raise”, a KeyError is raised. Defaults to “create”.

Methods

__init__(items[, min_freq, handle_unknown])

Construct the encoder by providing a list of items.

names()

Description of each non-zero entry.

to_sparse(items)

names() List[str][source]

Description of each non-zero entry.