LabelBinarizer
Binarize labels in a one-vs-all fashion.
Several regression and binary classification algorithms are available in scikit-learn. A simple way to extend these algorithms to the multi-class classification case is to use the so-called one-vs-all scheme.
At learning time, this simply consists in learning one regressor or binary classifier per class. In doing so, one needs to convert multi-class labels to binary labels (belong or does not belong to the class). LabelBinarizer makes this process easy with the transform method.
At prediction time, one assigns the class for which the corresponding model gave the greatest confidence. LabelBinarizer makes this easy with the inverse_transform method.
Read more in the User Guide.
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new LabelBinarizer(opts?: object): LabelBinarizer;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.neg_label? | number | Value with which negative labels must be encoded. Default Value 0 |
opts.pos_label? | number | Value with which positive labels must be encoded. Default Value 1 |
opts.sparse_output? | boolean | True if the returned array from transform is desired to be in sparse CSR format. Default Value false |
Returns
Defined in: generated/preprocessing/LabelBinarizer.ts:29 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/preprocessing/LabelBinarizer.ts:27 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/preprocessing/LabelBinarizer.ts:26 (opens in a new tab)
_py
PythonBridge
Defined in: generated/preprocessing/LabelBinarizer.ts:25 (opens in a new tab)
id
string
Defined in: generated/preprocessing/LabelBinarizer.ts:22 (opens in a new tab)
opts
any
Defined in: generated/preprocessing/LabelBinarizer.ts:23 (opens in a new tab)
Accessors
classes_
Holds the label for each class.
Signature
classes_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/LabelBinarizer.ts:311 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/preprocessing/LabelBinarizer.ts:55 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/preprocessing/LabelBinarizer.ts:59 (opens in a new tab)
sparse_input_
True if the input data to transform is given as a sparse matrix, false
otherwise.
Signature
sparse_input_(): Promise<boolean>;
Returns
Promise
<boolean
>
Defined in: generated/preprocessing/LabelBinarizer.ts:361 (opens in a new tab)
y_type_
Represents the type of the target data as evaluated by utils.multiclass.type_of_target. Possible type are ‘continuous’, ‘continuous-multioutput’, ‘binary’, ‘multiclass’, ‘multiclass-multioutput’, ‘multilabel-indicator’, and ‘unknown’.
Signature
y_type_(): Promise<string>;
Returns
Promise
<string
>
Defined in: generated/preprocessing/LabelBinarizer.ts:336 (opens in a new tab)
Methods
dispose()
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Signature
dispose(): Promise<void>;
Returns
Promise
<void
>
Defined in: generated/preprocessing/LabelBinarizer.ts:110 (opens in a new tab)
fit()
Fit label binarizer.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.y? | ArrayLike | Target values. The 2-d matrix should only contain 0 and 1, represents multilabel classification. |
Returns
Promise
<any
>
Defined in: generated/preprocessing/LabelBinarizer.ts:127 (opens in a new tab)
fit_transform()
Fit label binarizer/transform multi-class labels to binary labels.
The output of transform is sometimes referred to as the 1-of-K coding scheme.
Signature
fit_transform(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.y? | any | Target values. The 2-d matrix should only contain 0 and 1, represents multilabel classification. Sparse matrix can be CSR, CSC, COO, DOK, or LIL. |
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/LabelBinarizer.ts:162 (opens in a new tab)
init()
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Signature
init(py: PythonBridge): Promise<void>;
Parameters
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/preprocessing/LabelBinarizer.ts:68 (opens in a new tab)
inverse_transform()
Transform binary labels back to multi-class labels.
Signature
inverse_transform(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.Y? | ArrayLike | Target values. All sparse matrices are converted to CSR before inverse transformation. |
opts.threshold? | number | Threshold used in the binary and multi-label cases. Use 0 when Y contains the output of decision_function (classifier). Use 0.5 when Y contains the output of predict_proba. If undefined , the threshold is assumed to be half way between neg_label and pos_label. |
Returns
Promise
<any
>
Defined in: generated/preprocessing/LabelBinarizer.ts:195 (opens in a new tab)
set_output()
Set output container.
See Introducing the set_output API for an example on how to use the API.
Signature
set_output(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.transform? | "default" | "pandas" | Configure output of transform and fit\_transform . |
Returns
Promise
<any
>
Defined in: generated/preprocessing/LabelBinarizer.ts:243 (opens in a new tab)
transform()
Transform multi-class labels to binary labels.
The output of transform is sometimes referred to by some authors as the 1-of-K coding scheme.
Signature
transform(opts: object): Promise<ArrayLike>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.y? | any | Target values. The 2-d matrix should only contain 0 and 1, represents multilabel classification. Sparse matrix can be CSR, CSC, COO, DOK, or LIL. |
Returns
Promise
<ArrayLike
>
Defined in: generated/preprocessing/LabelBinarizer.ts:278 (opens in a new tab)