Skip to content

accuracy

Bases: metric

The accuracy evaluation metric.

The class inherits from the base metric class.

...

Attributes:

Name Type Description
name str, default = 'accuracy'

Name of the accuracy evaluation metric.

metric object

The accuracy evaluation metric calculation method.

Methods:

Name Description
__init__

It performs the initialization of the accuracy evaluation metric. Its internal metric calculation method is declared to be accuracy_score from sklearn.

evaluate

It implements the abstract evaluate method declared in the base metric class. The method calculates the accuracy score of the inputs.

__call__

It reimplements the abstract callable method declared in the base metric class.

Source code in tinybig/metric/classification_metric.py
class accuracy(metric):
    """
    The accuracy evaluation metric.

    The class inherits from the base metric class.

    ...

    Attributes
    ----------
    name: str, default = 'accuracy'
        Name of the accuracy evaluation metric.
    metric: object
        The accuracy evaluation metric calculation method.

    Methods
    ----------
    __init__
        It performs the initialization of the accuracy evaluation metric. Its internal metric calculation method is declared to be accuracy_score from sklearn.

    evaluate
        It implements the abstract evaluate method declared in the base metric class. The method calculates the accuracy score of the inputs.

    __call__
        It reimplements the abstract callable method declared in the base metric class.

    """
    def __init__(self, name: str = 'accuracy'):
        """
        The initialization method of the accuracy evaluation metric.

        It initializes an accuracy evaluation metric object based on the input metric name.
        This method will also call the initialization method of the base class as well.
        The metric calculation approach is initialized as the sklearn.metrics.accuracy_score.

        Parameters
        ----------
        name: str, default = 'accuracy'
            The name of the evaluation metric.
        """
        super().__init__(name=name)
        self.metric = accuracy_score

    def evaluate(self, y_true: list, y_pred: list, *args, **kwargs):
        """
        The evaluate method of the accuracy evaluation metric class.

        It calculates the accuracy scores based on the provided input parameters "y_true" and "y_pred".
        The method will return calculated accuracy score as the output.

        Examples
        ----------
        >>> from tinybig.metric import accuracy as accuracy_metric
        >>> acc_metric = accuracy_metric(name='accuracy_metric')
        >>> y_true = [1, 1, 0, 0]
        >>> y_pred = [1, 1, 0, 1]
        >>> acc_metric.evaluate(y_pred=y_pred, y_true=y_true)
        0.75

        Parameters
        ----------
        y_true: list
            The list of true labels of data instances.
        y_pred: list
            The list of predicted labels of data instances.
        args: list
            Other parameters
        kwargs: dict
            Other parameters

        Returns
        -------
        float | list
            The calculated accuracy score of the input parameters.
        """
        return self.metric(y_true=y_true, y_pred=y_pred)

    def __call__(self, y_true: list, y_pred: list, *args, **kwargs):
        """
        The callable method of the accuracy metric class.

        It re-implements the build-in callable method.
        This method will call the evaluate method to calculate the accuracy of the input parameters.

        Examples
        ----------
        >>> from tinybig.metric import accuracy as accuracy_metric
        >>> acc_metric = accuracy_metric(name='accuracy_metric')
        >>> y_true = [1, 1, 0, 0]
        >>> y_pred = [1, 1, 0, 1]
        >>> acc_metric(y_pred=y_pred, y_true=y_true)
        0.75

        Parameters
        ----------
        y_true: list
            The list of true labels of data instances.
        y_pred: list
            The list of predicted labels of data instances.
        args: list
            Other parameters
        kwargs: dict
            Other parameters

        Returns
        -------
        float | list
            The calculated accuracy score of the input parameters.
        """
        return self.evaluate(y_true=y_true, y_pred=y_pred, *args, **kwargs)

__call__(y_true, y_pred, *args, **kwargs)

The callable method of the accuracy metric class.

It re-implements the build-in callable method. This method will call the evaluate method to calculate the accuracy of the input parameters.

Examples:

>>> from tinybig.metric import accuracy as accuracy_metric
>>> acc_metric = accuracy_metric(name='accuracy_metric')
>>> y_true = [1, 1, 0, 0]
>>> y_pred = [1, 1, 0, 1]
>>> acc_metric(y_pred=y_pred, y_true=y_true)
0.75

Parameters:

Name Type Description Default
y_true list

The list of true labels of data instances.

required
y_pred list

The list of predicted labels of data instances.

required
args

Other parameters

()
kwargs

Other parameters

{}

Returns:

Type Description
float | list

The calculated accuracy score of the input parameters.

Source code in tinybig/metric/classification_metric.py
def __call__(self, y_true: list, y_pred: list, *args, **kwargs):
    """
    The callable method of the accuracy metric class.

    It re-implements the build-in callable method.
    This method will call the evaluate method to calculate the accuracy of the input parameters.

    Examples
    ----------
    >>> from tinybig.metric import accuracy as accuracy_metric
    >>> acc_metric = accuracy_metric(name='accuracy_metric')
    >>> y_true = [1, 1, 0, 0]
    >>> y_pred = [1, 1, 0, 1]
    >>> acc_metric(y_pred=y_pred, y_true=y_true)
    0.75

    Parameters
    ----------
    y_true: list
        The list of true labels of data instances.
    y_pred: list
        The list of predicted labels of data instances.
    args: list
        Other parameters
    kwargs: dict
        Other parameters

    Returns
    -------
    float | list
        The calculated accuracy score of the input parameters.
    """
    return self.evaluate(y_true=y_true, y_pred=y_pred, *args, **kwargs)

__init__(name='accuracy')

The initialization method of the accuracy evaluation metric.

It initializes an accuracy evaluation metric object based on the input metric name. This method will also call the initialization method of the base class as well. The metric calculation approach is initialized as the sklearn.metrics.accuracy_score.

Parameters:

Name Type Description Default
name str

The name of the evaluation metric.

'accuracy'
Source code in tinybig/metric/classification_metric.py
def __init__(self, name: str = 'accuracy'):
    """
    The initialization method of the accuracy evaluation metric.

    It initializes an accuracy evaluation metric object based on the input metric name.
    This method will also call the initialization method of the base class as well.
    The metric calculation approach is initialized as the sklearn.metrics.accuracy_score.

    Parameters
    ----------
    name: str, default = 'accuracy'
        The name of the evaluation metric.
    """
    super().__init__(name=name)
    self.metric = accuracy_score

evaluate(y_true, y_pred, *args, **kwargs)

The evaluate method of the accuracy evaluation metric class.

It calculates the accuracy scores based on the provided input parameters "y_true" and "y_pred". The method will return calculated accuracy score as the output.

Examples:

>>> from tinybig.metric import accuracy as accuracy_metric
>>> acc_metric = accuracy_metric(name='accuracy_metric')
>>> y_true = [1, 1, 0, 0]
>>> y_pred = [1, 1, 0, 1]
>>> acc_metric.evaluate(y_pred=y_pred, y_true=y_true)
0.75

Parameters:

Name Type Description Default
y_true list

The list of true labels of data instances.

required
y_pred list

The list of predicted labels of data instances.

required
args

Other parameters

()
kwargs

Other parameters

{}

Returns:

Type Description
float | list

The calculated accuracy score of the input parameters.

Source code in tinybig/metric/classification_metric.py
def evaluate(self, y_true: list, y_pred: list, *args, **kwargs):
    """
    The evaluate method of the accuracy evaluation metric class.

    It calculates the accuracy scores based on the provided input parameters "y_true" and "y_pred".
    The method will return calculated accuracy score as the output.

    Examples
    ----------
    >>> from tinybig.metric import accuracy as accuracy_metric
    >>> acc_metric = accuracy_metric(name='accuracy_metric')
    >>> y_true = [1, 1, 0, 0]
    >>> y_pred = [1, 1, 0, 1]
    >>> acc_metric.evaluate(y_pred=y_pred, y_true=y_true)
    0.75

    Parameters
    ----------
    y_true: list
        The list of true labels of data instances.
    y_pred: list
        The list of predicted labels of data instances.
    args: list
        Other parameters
    kwargs: dict
        Other parameters

    Returns
    -------
    float | list
        The calculated accuracy score of the input parameters.
    """
    return self.metric(y_true=y_true, y_pred=y_pred)