mojolearn.LabelBinarizer#

class mojolearn.LabelBinarizer(*, neg_label=0, pos_label=1, sparse_output=False)[source]#

Bases: _PrepBase

Binarize labels in a one-vs-all fashion.

Follows scikit-learn’s LabelBinarizer. transform returns an int32 matrix with one column per class holding pos_label for the row’s class and neg_label elsewhere; with two classes it returns a single column (positive for the second class), and with one class a single column of neg_label. A label not seen in fit becomes a row of neg_label. Numeric and string labels are supported.

A 2-D y with more than one column and at most two distinct integer values is treated as a multilabel indicator, as in scikit-learn: classes_ are the column indices, and each nonzero entry becomes pos_label and each zero neg_label.

Parameters:
  • neg_label (int, default 0) – Value for negative entries.

  • pos_label (int, default 1) – Value for positive entries; must be greater than neg_label (ValueError otherwise).

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

Variables:
  • classes_ (array or list) – Class labels.

  • y_type_ (str) – 'binary', 'multiclass' or 'multilabel-indicator'.

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

Notes

inverse_transform(Y, threshold=None) takes the largest column for multiclass output and applies threshold (by default halfway between neg_label and pos_label) for binary and multilabel output, as in scikit-learn.

Examples

>>> import numpy as np, mojolearn
>>> lb = mojolearn.LabelBinarizer().fit(np.array([1, 2, 6, 4, 2]))
>>> lb.transform(np.array([1, 6]))
__init__(*, neg_label=0, pos_label=1, 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(Y[, threshold])

set_params(**params)

Set constructor parameters.

transform(y)

fit_transform(y)[source]#

Fit to X, then transform X.

Returns:

array – The transformed data.