towhee.hub.builtin.operators.feature_engineer.num_discretizer

class towhee.hub.builtin.operators.feature_engineer.num_discretizer(name: Optional[str] = None, n_bins=10, encode='onehot', strategy='quantile')[source]

Bases: StatefulOperator

Bin numerical features into intervals.

Examples:

>>> from towhee import DataCollection, Entity
>>> dc = (
...     DataCollection.range(10).map(lambda x: Entity(a=x))
...         .set_training()
...         .num_discretizer['a', 'b'](name='discretizer', n_bins=3)
... )
>>> [x.b.nonzero()[1][0] for x in dc.to_list()]
[0, 0, 0, 1, 1, 1, 2, 2, 2, 2]

Methods

feed

fit

predict

set_state

set_training

Attributes

flag

key

metainfo

shared_type

__call__(*args, **kws)

The framework calls __call__ function repeatedly for every input data.

Args:

Returns:

Raises:

An exception during __init__ can terminate the graph run.

__init__(name: Optional[str] = None, n_bins=10, encode='onehot', strategy='quantile')[source]

Init operator, before a graph starts, the framework will call Operator __init__ function.

Args:

Raises:

An exception during __init__ can terminate the graph run.