Class: 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.
Constructors
new LabelBinarizer()
new LabelBinarizer(
opts
?):LabelBinarizer
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.neg_label ? | number | Value with which negative labels must be encoded. |
opts.pos_label ? | number | Value with which positive labels must be encoded. |
opts.sparse_output ? | boolean | True if the returned array from transform is desired to be in sparse CSR format. |
Returns LabelBinarizer
Defined in generated/preprocessing/LabelBinarizer.ts:29
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/preprocessing/LabelBinarizer.ts:27 |
_isInitialized | boolean | false | generated/preprocessing/LabelBinarizer.ts:26 |
_py | PythonBridge | undefined | generated/preprocessing/LabelBinarizer.ts:25 |
id | string | undefined | generated/preprocessing/LabelBinarizer.ts:22 |
opts | any | undefined | generated/preprocessing/LabelBinarizer.ts:23 |
Accessors
classes_
Get Signature
get classes_():
Promise
<ArrayLike
>
Holds the label for each class.
Returns Promise
<ArrayLike
>
Defined in generated/preprocessing/LabelBinarizer.ts:375
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/preprocessing/LabelBinarizer.ts:55
sparse_input_
Get Signature
get sparse_input_():
Promise
<boolean
>
false
otherwise.
Returns Promise
<boolean
>
Defined in generated/preprocessing/LabelBinarizer.ts:425
y_type_
Get Signature
get y_type_():
Promise
<string
>
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’.
Returns Promise
<string
>
Defined in generated/preprocessing/LabelBinarizer.ts:400
Methods
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/preprocessing/LabelBinarizer.ts:107
fit()
fit(
opts
):Promise
<any
>
Fit label binarizer.
Parameters
Parameter | 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:124
fit_transform()
fit_transform(
opts
):Promise
<ArrayLike
>
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.
Parameters
Parameter | 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:158
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRequest encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/preprocessing/LabelBinarizer.ts:192
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/preprocessing/LabelBinarizer.ts:68
inverse_transform()
inverse_transform(
opts
):Promise
<any
>
Transform binary labels back to multi-class labels.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
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. |
opts.Y ? | ArrayLike | Target values. All sparse matrices are converted to CSR before inverse transformation. |
Returns Promise
<any
>
Defined in generated/preprocessing/LabelBinarizer.ts:226
set_inverse_transform_request()
set_inverse_transform_request(
opts
):Promise
<any
>
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:
Parameters
Parameter | 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:273
set_output()
set_output(
opts
):Promise
<any
>
Set output container.
See Introducing the set_output API for an example on how to use the API.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.transform ? | "default" | "pandas" | "polars" | Configure output of transform and fit_transform . |
Returns Promise
<any
>
Defined in generated/preprocessing/LabelBinarizer.ts:309
transform()
transform(
opts
):Promise
<ArrayLike
>
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.
Parameters
Parameter | 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
>