mojolearn.LabelBinarizer#
- class mojolearn.LabelBinarizer(*, neg_label=0, pos_label=1, sparse_output=False)[source]#
Bases:
_PrepBaseBinarize labels in a one-vs-all fashion.
Follows scikit-learn’s
LabelBinarizer.transformreturns an int32 matrix with one column per class holdingpos_labelfor the row’s class andneg_labelelsewhere; with two classes it returns a single column (positive for the second class), and with one class a single column ofneg_label. A label not seen in fit becomes a row ofneg_label. Numeric and string labels are supported.A 2-D
ywith 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 becomespos_labeland each zeroneg_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(ValueErrorotherwise).sparse_output (bool, default False) – Must be False; True raises
NotImplementedError.
- Variables:
Notes
inverse_transform(Y, threshold=None)takes the largest column for multiclass output and appliesthreshold(by default halfway betweenneg_labelandpos_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]))
Methods
fit(y)Fit to
X, then transformX.get_params([deep])Return the constructor parameters as a dict.
inverse_transform(Y[, threshold])set_params(**params)Set constructor parameters.
transform(y)