I'm trying to infer prediction ratings from an item-item similarity matrix where the similarity score is calculated via the log-likelihood ratio (LLR). I'm using this code snippet to calculate the LLR (taken from this medium article):

import numpy as np

def xLogX(x):
    return x * np.log(x) if x != 0 else 0.0

def entropy(x1, x2=0, x3=0, x4=0):
    return xLogX(x1 + x2 + x3 + x4) - xLogX(x1) - xLogX(x2) - xLogX(x3) - xLogX(x4)

def LLR(k11, k12, k21, k22):
    rowEntropy = entropy(k11 + k12, k21 + k22)
    columnEntropy = entropy(k11 + k21, k12 + k22)
    matrixEntropy = entropy(k11, k12, k21, k22)
    if rowEntropy + columnEntropy < matrixEntropy:
        return 0.0
    return 2.0 * (rowEntropy + columnEntropy - matrixEntropy)

def rootLLR(k11, k12, k21, k22):
    llr = LLR(k11, k12, k21, k22)
    sqrt = np.sqrt(llr)
    if k11 * 1.0 / (k11 + k12) < k21 * 1.0 / (k21 + k22):
        sqrt = -sqrt
    return sqrt

rootLLR(100, 10, 10, 50000) # 36.18239222320234

To get a better understanding of the LLR check out this article by Ted Dunning. The issue I'm having is the LLR scores are not bounded (higher is better). For example, using the cosine similarity, the scores are bound from -1 to 1. Whereas with LLR this is not the case so calculating the weighted sum for rating prediction is difficult.

I've seen this paper (page 6) which normalises the LLR score but does not state how. The table from the paper is shown below.

enter image description here



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.