nord vpnnord vpn
Ad

Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.2 kB
1
Indexable
Never
def calculate_map(actual, predicted):
    """
    Calculate Mean Average Precision (MAP) for the recommendations.
    
    Args:
        actual (str or int): Actual user who resolved the ticket.
        predicted (list): List of recommended users.
    
    Returns:
        float: Mean Average Precision (MAP) score.
    """
    avg_precision = 0.0
    num_correct = 0
    
    if actual in predicted:
        num_correct += 1
        precision_at_k = num_correct / (predicted.index(actual) + 1)
        avg_precision += precision_at_k
    
    if num_correct == 0:
        return 0.0
    
    return avg_precision


def calculate_topk_accuracy(actual, predicted, k):
    """
    Calculate Top-k Accuracy for the recommendations.
    
    Args:
        actual (str or int): Actual user who resolved the ticket.
        predicted (list): List of recommended users.
        k (int): Number of top-k recommendations to consider.
    
    Returns:
        float: Top-k Accuracy score.
    """
    topk_predictions = predicted[:k]
    if actual in topk_predictions:
        return 1.0
    else:
        return 0.0


nord vpnnord vpn
Ad