olpy.preprocessing.LabelEncoder

class olpy.preprocessing.LabelEncoder(positive_label=1)[source]

Bases: object

Encodes an output vector to match the specifications.

Given that online learning algorithms usually work on output vectors with entries (-1, 1), this function performs this action for the user.

y

the data to be transformed.

Type

array of ndarray

positive_label

The number in the output field that represents the positive label. The value passed should be different than -1. Defaults to 1.

Type

int, optional

labels

represents the labels that are present in the dataset. This can be used at prediction time.

Type

tuple

Methods

fit

Fits the output vector y.

fit_transform

Fits and transforms the data.

transform

Transforms the data.

fit(y)[source]

Fits the output vector y.

This method parses the parsed value and sets the necessary values to transform it later.

Parameters

y (list or numpy.ndarray) – the data to be transformed.

Returns

the current instance.

Return type

self

Raises
  • ValueError – if the number of labels is different than 2.

  • AssertionError – if the positive label is not found in the labels.

fit_transform(y, return_labels=True)[source]

Fits and transforms the data.

Combines the actions of fit and transform methods.

Parameters
  • return_labels (bool, optional) – whether the labels should be returned or not. Default True.

  • y (array of ndarray) – the data to be transformed.

Returns

numpy.ndarray if return_labels is True else None

Raises
  • ValueError – if the number of labels is different than 2.

  • AssertionError – if the positive label is not found in the labels.

  • NotFittedError if the encoder was not already fitted.

transform(return_labels=True)[source]

Transforms the data.

Based on the information collected while fitting, this fuction returns the transformed labels that can be used directly for training.

Parameters

return_labels (bool, optional) – whether the labels should be returned or not. Default True.

Returns

numpy.ndarray if return_labels is True else None

Raises

NotFittedError if the encoder was not already fitted.