model/utils.py
def p_at_k(preds, labels, k):
    """
    Compute the top K precision.

    Args:
        preds: A numpy array of predicted values.
        labels: A numpy array of actual labels.
        k: An integer indicating the P@K
    """
    concatenated = np.concatenate([np.expand_dims(preds, axis=1),
                                   np.expand_dims(labels, axis=1)], axis=1)
    return concatenated[np.argsort(concatenated[:, 0])[::-1]][:k]

    Compute the top K precision.

    Args:
        preds: A numpy array of predicted values.
        labels: A numpy array of actual labels.
        k: An integer indicating the P@K
    
Compute the top K precision.
Compute the top K precision .
def p_at_k(preds, labels, k):
    concatenated = np.concatenate([np.expand_dims(preds, axis=1),
                                   np.expand_dims(labels, axis=1)], axis=1)
    return concatenated[np.argsort(concatenated[:, 0])[::-1]][:k]
def p_at_k ( preds , labels , k ) : concatenated = np . concatenate ( [ np . expand_dims ( preds , axis = 1 ) , np . expand_dims ( labels , axis = 1 ) ] , axis = 1 ) return concatenated [ np . argsort ( concatenated [ : , 0 ] ) [ : : - 1 ] ] [ : k ]
Compute the top K precision.
Compute the top K precision .
"""
    Compute the top K precision.

    Args:
        preds: A numpy array of predicted values.
        labels: A numpy array of actual labels.
        k: An integer indicating the P@K
    """
preds
A numpy array of predicted values.
A numpy array of predicted values .
labels
A numpy array of actual labels.
A numpy array of actual labels .
k
An integer indicating the P@K
An integer indicating the P@K