task#

Note

This module is not intended to be used directly by users. It is used by the cleanlab.datalab.datalab module.

This module contains the Task enum, which internally represents the tasks supported by Datalab, so that the appropriate task-specific logic can be applied. This class and associated naming conventions are subject to change and is not meant to be used by users.

Classes:

Task(value[, names, module, qualname, type, ...])

Represents a task supported by Datalab.

class cleanlab.datalab.internal.task.Task(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

Represents a task supported by Datalab.

Datalab supports the following tasks:

  • Classification: for predicting discrete class labels.

  • Regression: for predicting continuous numerical values.

  • Multilabel: for predicting multiple binary labels simultaneously.

Example

>>> task = Task.CLASSIFICATION
>>> task
<Task.CLASSIFICATION: 'classification'>

Attributes:

CLASSIFICATION

Classification task.

REGRESSION

Regression task.

MULTILABEL

Multilabel task.

is_classification

Checks if the task is classification.

is_regression

Checks if the task is regression.

is_multilabel

Checks if the task is multilabel.

Methods:

from_str(task_str)

Converts a string representation of a task to a Task enum value.

__contains__(member)

Return True if member is a member of this enum raises TypeError if member is not an enum member

__getitem__(name)

Return the member matching name.

__iter__()

Return members in definition order.

__len__()

Return the number of members (no aliases)

CLASSIFICATION = 'classification'#

Classification task.

REGRESSION = 'regression'#

Regression task.

MULTILABEL = 'multilabel'#

Multilabel task.

classmethod from_str(task_str)[source]#

Converts a string representation of a task to a Task enum value.

Parameters:

task_str (str) – The string representation of the task.

Return type:

Task

Returns:

Task – The corresponding Task enum value.

Raises:

ValueError : – If the provided task_str is not a valid task supported by Datalab.

Examples

>>> Task.from_str("classification")
<Task.CLASSIFICATION: 'classification'>
>>> print(Task.from_str("regression"))
regression
property is_classification#

Checks if the task is classification.

Returns:

bool – True if the task is classification, False otherwise.

Examples

>>> task = Task.CLASSIFICATION
>>> print(task.is_classification)
True
classmethod __contains__(member)#

Return True if member is a member of this enum raises TypeError if member is not an enum member

note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum

classmethod __getitem__(name)#

Return the member matching name.

classmethod __iter__()#

Return members in definition order.

classmethod __len__()#

Return the number of members (no aliases)

property is_regression#

Checks if the task is regression.

Returns:

bool – True if the task is regression, False otherwise.

Examples

>>> task = Task.CLASSIFICATION
>>> print(task.is_regression)
False
property is_multilabel#

Checks if the task is multilabel.

Returns:

bool – True if the task is multilabel, False otherwise.

Examples

>>> task = Task.CLASSIFICATION
>>> print(task.is_multilabel)
False