src/rime/metrics/__init__.py
def evaluate_assigned(target_csr, assigned_csr, score_mat=None, axis=None,
                      min_total_recs=0, device="cpu"):
    """ compare targets and recommendation assignments on user-item matrix
    """
    hit = _multiply(target_csr, assigned_csr)
    min_total_recs = max(min_total_recs, assigned_csr.sum())

    out = {
        'prec': hit.sum() / min_total_recs,
        'recs/user': assigned_csr.sum() / assigned_csr.shape[0],
        'item_cov': (assigned_csr.sum(axis=0) > 0).mean(),  # 1 by n_items
        'item_ppl': perplexity(assigned_csr.sum(axis=0)),
        'user_cov': (assigned_csr.sum(axis=1) > 0).mean(),  # n_users by 1
        'user_ppl': perplexity(assigned_csr.sum(axis=1)),
    }

    if score_mat is not None:
        if hasattr(score_mat, "collate_fn"):
            obj_sum = float(score_op(score_mat * assigned_csr, "sum", device))
        else:
            obj_sum = _multiply(assigned_csr, score_mat).sum()
        out['obj_mean'] = float(obj_sum / min_total_recs)

    if axis is not None:
        hit_axis = np.ravel(hit.sum(axis=axis))
        ideal = np.ravel(target_csr.sum(axis=axis))
        out['recall'] = (hit_axis / np.fmax(1, ideal)).mean()

    return out
 compare targets and recommendation assignments on user-item matrix
    
compare targets and recommendation assignments on user-item matrix
compare targets and recommendation assignments on user - item matrix
def evaluate_assigned(target_csr, assigned_csr, score_mat=None, axis=None,
                      min_total_recs=0, device="cpu"):
    hit = _multiply(target_csr, assigned_csr)
    min_total_recs = max(min_total_recs, assigned_csr.sum())
    out = {
        'prec': hit.sum() / min_total_recs,
        'recs/user': assigned_csr.sum() / assigned_csr.shape[0],
        'item_cov': (assigned_csr.sum(axis=0) > 0).mean(),  
        'item_ppl': perplexity(assigned_csr.sum(axis=0)),
        'user_cov': (assigned_csr.sum(axis=1) > 0).mean(),  
        'user_ppl': perplexity(assigned_csr.sum(axis=1)),
    }
    if score_mat is not None:
        if hasattr(score_mat, "collate_fn"):
            obj_sum = float(score_op(score_mat * assigned_csr, "sum", device))
        else:
            obj_sum = _multiply(assigned_csr, score_mat).sum()
        out['obj_mean'] = float(obj_sum / min_total_recs)
    if axis is not None:
        hit_axis = np.ravel(hit.sum(axis=axis))
        ideal = np.ravel(target_csr.sum(axis=axis))
        out['recall'] = (hit_axis / np.fmax(1, ideal)).mean()
    return out
def evaluate_assigned ( target_csr , assigned_csr , score_mat = None , axis = None , min_total_recs = 0 , device = "cpu" ) : hit = _multiply ( target_csr , assigned_csr ) min_total_recs = max ( min_total_recs , assigned_csr . sum ( ) ) out = { 'prec' : hit . sum ( ) / min_total_recs , 'recs/user' : assigned_csr . sum ( ) / assigned_csr . shape [ 0 ] , 'item_cov' : ( assigned_csr . sum ( axis = 0 ) > 0 ) . mean ( ) , 'item_ppl' : perplexity ( assigned_csr . sum ( axis = 0 ) ) , 'user_cov' : ( assigned_csr . sum ( axis = 1 ) > 0 ) . mean ( ) , 'user_ppl' : perplexity ( assigned_csr . sum ( axis = 1 ) ) , } if score_mat is not None : if hasattr ( score_mat , "collate_fn" ) : obj_sum = float ( score_op ( score_mat * assigned_csr , "sum" , device ) ) else : obj_sum = _multiply ( assigned_csr , score_mat ) . sum ( ) out [ 'obj_mean' ] = float ( obj_sum / min_total_recs ) if axis is not None : hit_axis = np . ravel ( hit . sum ( axis = axis ) ) ideal = np . ravel ( target_csr . sum ( axis = axis ) ) out [ 'recall' ] = ( hit_axis / np . fmax ( 1 , ideal ) ) . mean ( ) return out
compare targets and recommendation assignments on user-item matrix
compare targets and recommendation assignments on user - item matrix
""" compare targets and recommendation assignments on user-item matrix
    """ # 1 by n_items # n_users by 1
target_csr
assigned_csr
score_mat
axis
min_total_recs
device