elegy/metrics/binary_accuracy.py
def binary_accuracy(
    y_true: np.ndarray, y_pred: np.ndarray, threshold: float = 0.5
) -> np.ndarray:
    """
    Calculates how often predictions matches binary labels.

    Standalone usage:

    ```python
    y_true = np.array([[1], [1], [0], [0]])
    y_pred = np.array([[1], [1], [0], [0]])
    m = elegy.metrics.binary_accuracy(y_true, y_pred)
    assert m.shape == (4,)
    ```
    Arguments:
        y_true: Ground truth values. shape = `[batch_size, d0, .. dN]`.
        y_pred: The predicted values. shape = `[batch_size, d0, .. dN]`.
        threshold: Float representing the threshold for deciding whether
            prediction values are 1 or 0.

    Returns:
        Binary accuracy values. shape = `[batch_size, d0, .. dN-1]`
    """
    assert abs(y_pred.ndim - y_true.ndim) <= 1

    y_true, y_pred = utils.maybe_expand_dims(y_true, y_pred)

    y_pred = y_pred > threshold
    return jnp.mean(y_true == y_pred, axis=-1)

    Calculates how often predictions matches binary labels.

    Standalone usage:

    ```python
    y_true = np.array([[1], [1], [0], [0]])
    y_pred = np.array([[1], [1], [0], [0]])
    m = elegy.metrics.binary_accuracy(y_true, y_pred)
    assert m.shape == (4,)
    ```
    Arguments:
        y_true: Ground truth values. shape = `[batch_size, d0, .. dN]`.
        y_pred: The predicted values. shape = `[batch_size, d0, .. dN]`.
        threshold: Float representing the threshold for deciding whether
            prediction values are 1 or 0.

    Returns:
        Binary accuracy values. shape = `[batch_size, d0, .. dN-1]`
    
Calculates how often predictions matches binary labels.
Standalone usage.


Calculates how often predictions matches binary labels . Standalone usage .
def binary_accuracy(
    y_true: np.ndarray, y_pred: np.ndarray, threshold: float = 0.5
) -> np.ndarray:
    assert abs(y_pred.ndim - y_true.ndim) <= 1
    y_true, y_pred = utils.maybe_expand_dims(y_true, y_pred)
    y_pred = y_pred > threshold
    return jnp.mean(y_true == y_pred, axis=-1)
def binary_accuracy ( y_true : np . ndarray , y_pred : np . ndarray , threshold : float = 0.5 ) -> np . ndarray : assert abs ( y_pred . ndim - y_true . ndim ) <= 1 y_true , y_pred = utils . maybe_expand_dims ( y_true , y_pred ) y_pred = y_pred > threshold return jnp . mean ( y_true == y_pred , axis = - 1 )
Calculates how often predictions matches binary labels.
Calculates how often predictions matches binary labels .
"""
    Calculates how often predictions matches binary labels.

    Standalone usage:

    ```python
    y_true = np.array([[1], [1], [0], [0]])
    y_pred = np.array([[1], [1], [0], [0]])
    m = elegy.metrics.binary_accuracy(y_true, y_pred)
    assert m.shape == (4,)
    ```
    Arguments:
        y_true: Ground truth values. shape = `[batch_size, d0, .. dN]`.
        y_pred: The predicted values. shape = `[batch_size, d0, .. dN]`.
        threshold: Float representing the threshold for deciding whether
            prediction values are 1 or 0.

    Returns:
        Binary accuracy values. shape = `[batch_size, d0, .. dN-1]`
    """
Binary accuracy values. shape = `[batch_size, d0, ..
Binary accuracy values . shape = ` [ batch_size d0 ..
y_true
np.ndarray
Ground truth values. shape = `[batch_size, d0, .. dN]`.
Ground truth values . shape = ` [ batch_size d0 .. dN ] ` .
y_pred
np.ndarray
The predicted values. shape = `[batch_size, d0, .. dN]`.
The predicted values . shape = ` [ batch_size d0 .. dN ] ` .
threshold
float
Float representing the threshold for deciding whether
prediction values are 1 or 0.
Float representing the threshold for deciding whether prediction values are 1 or 0 .