mojolearn.MultiLabelBinarizer#

class mojolearn.MultiLabelBinarizer(*, classes=None, sparse_output=False)[source]#

Bases: _PrepBase

Convert sets of labels to a binary indicator matrix.

Follows scikit-learn’s MultiLabelBinarizer. y is an iterable of label collections, one per sample. transform returns an int32 matrix with a 1 where the sample has the class. A label not seen in fit is ignored (scikit-learn also warns). Numeric and string labels are supported.

Parameters:
  • classes (array-like, default None) – Class labels in the order of the output columns. None uses the sorted union of all labels in fit.

  • sparse_output (bool, default False) – Must be False; True raises NotImplementedError.

Variables:
  • classes_ (array or list) – Class labels: an int64 array for integer labels, a float64 array for real labels, otherwise a list.

  • numeric_mode_ (str) – Numeric mode at fit time; transform runs in the same mode.

Notes

inverse_transform returns a list with one tuple of labels per row.

Examples

>>> import mojolearn
>>> mlb = mojolearn.MultiLabelBinarizer()
>>> mlb.fit_transform([[1, 2], [3], [2, 3]])
__init__(*, classes=None, sparse_output=False)[source]#

Methods

fit(y)

fit_transform(y)

Fit to X, then transform X.

get_params([deep])

Return the constructor parameters as a dict.

inverse_transform(yt)

set_params(**params)

Set constructor parameters.

transform(y)

fit_transform(y)[source]#

Fit to X, then transform X.

Returns:

array – The transformed data.