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)
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)
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Signature
get_metadata_routing(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.routing? | any | A MetadataRequest encapsulating routing information. |
Returns
Promise
<any
>
Defined in: generated/preprocessing/LabelBinarizer.ts:197 (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:232 (opens in a new tab)
set_inverse_transform_request()
Request metadata passed to the inverse\_transform
method.
Note that this method is only relevant if enable\_metadata\_routing=True
(see sklearn.set\_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Signature
set_inverse_transform_request(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.threshold? | string | boolean | Metadata routing for threshold parameter in inverse\_transform . |
Returns
Promise
<any
>
Defined in: generated/preprocessing/LabelBinarizer.ts:282 (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:320 (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:355 (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:388 (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_
false
otherwise.
Signature
sparse_input_(): Promise<boolean>;
Returns
Promise
<boolean
>
Defined in: generated/preprocessing/LabelBinarizer.ts:438 (opens in a new tab)
y_type_
Represents the type of the target data as evaluated by 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:413 (opens in a new tab)