ExtLabelEncoder#

class skactiveml.utils.ExtLabelEncoder(classes=None, missing_label=nan, target_type='single-output')[source]#

Bases: BaseEstimator

Encode class labels with integers in [0, …, n_classes-1] and use -1 for unlabeled.

Parameters:
classesarray-like of shape (n_classes,) or a list of such array-likes, default=None
  • If classes is not nested (None or one-dimensional), a single task problem is assumed such that y can be shape (n_samples,) or (n_samples, n_annotators). Same encoder is applied to all entries.

  • If classes is nested, target_type must be “multi-label”, and y must contain one column per binary class vocabulary.

missing_labelscalar or string or np.nan or None, default=np.nan

Value to represent a missing label.

target_type“single-output” or “multi-label”, default=”single-output”

Resolved target type controlling whether one shared encoder or one encoder per label is used.

Methods

fit(y)

Fit label encoder.

fit_transform(y)

Fit label encoder and return encoded labels.

inverse_transform(y, *[, prefer_class_dtype])

Transform labels back to original encoding.

transform(y)

Transform labels to new class encoding.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_inverse_transform_request(*[, ...])

Configure whether metadata should be requested to be passed to the inverse_transform method.

set_params(**params)

Set the parameters of this estimator.

ExtLabelEncoder.fit(y)[source]#

Fit label encoder.

Parameters:
yarray-like of shape (n_samples,) or (n_samples, n_outputs)

Class labels.

Returns:
selfExtLabelEncoder

Returns an instance of ExtLabelEncoder.

ExtLabelEncoder.fit_transform(y)[source]#

Fit label encoder and return encoded labels.

Parameters:
yarray-like of shape (n_samples,) or (n_samples, n_outputs)

Class labels.

Returns:
ynp.ndarray shape (n_samples,) or (n_samples, n_outputs)

Class labels.

ExtLabelEncoder.inverse_transform(y, *, prefer_class_dtype=False)[source]#

Transform labels back to original encoding.

Parameters:
ynumpy array of shape (n_samples,) or (n_samples, n_outputs)

Encoded class labels.

prefer_class_dtypebool, default=False

If True, decode fully observed targets directly into the class dtype (the common dtype of the vocabularies for multi-label targets). Targets containing missing entries still use a dtype that also holds the missing label. If False, always use that missing-capable dtype, preserving the default behavior.

Returns:
y_decnp.ndarray of shape (n_samples,) or (n_samples, n_outputs)

Decoded (original) class labels. Unless prefer_class_dtype=True and no entries are missing, the dtype is NumPy’s common dtype of the classes and the missing label, or object for missing_label=None.

ExtLabelEncoder.transform(y)[source]#

Transform labels to new class encoding.

Parameters:
yarray-like of shape (n_samples,) or (n_samples, n_outputs)

Original class labels.

Returns:
y_encarray-like of shape (n_samples) or (n_samples, n_outputs)

Encoded class labels.

ExtLabelEncoder.get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

ExtLabelEncoder.get_params(deep=True)#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

ExtLabelEncoder.set_inverse_transform_request(*, prefer_class_dtype: bool | None | str = '$UNCHANGED$') → ExtLabelEncoder#

Configure whether metadata should be requested to be passed to the inverse_transform method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to inverse_transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to inverse_transform.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
prefer_class_dtypestr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for prefer_class_dtype parameter in inverse_transform.

Returns:
selfobject

The updated object.

ExtLabelEncoder.set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.