pipeline/evaluate.py
def similarity_matrices(found_list, ground_list):
    """Compute  the recall, precision, f1-score and jaccard similarity.

    :param list found_list: List of found communities to evaluate.
    :param list ground_list: List of ground truth communities to compare
        against.
    :return: tuple of (recall, precision, f1-score, and jaccard similarity)
    """
    gsets = [set(g) for g in ground_list]
    glens = np.array([float(len(g)) for g in ground_list])
    flens = np.matrix([float(len(f)) for f in found_list])
    flens = np.array(np.tile(flens.transpose(), len(ground_list)))

    logging.info('calculating true positive values')
    tp_mat = np.zeros((len(found_list), len(ground_list)))
    for i, found in enumerate(found_list):
        tp_mat[i] = [len(ground.intersection(found)) for ground in gsets]

    logging.info('calculating found/ground set union sizes')
    union_mat = np.zeros((len(found_list), len(ground_list)))
    for i, found in enumerate(found_list):
        union_mat[i] = [len(ground.union(found)) for ground in gsets]

    logging.info('calculating recall matrix')
    recall = tp_mat / glens

    logging.info('calculating precision matrix')
    precision = tp_mat / flens

    logging.info('calculating f1-score matrix')
    f1 = 2 * recall * precision / (recall + precision)
    f1[np.isnan(f1)] = 0.0  # fill NaN values from 0 division

    logging.info('calculating jaccard coefficient matrix')
    jaccard = tp_mat / union_mat

    return (recall, precision, f1, jaccard)
Compute  the recall, precision, f1-score and jaccard similarity.

    :param list found_list: List of found communities to evaluate.
    :param list ground_list: List of ground truth communities to compare
        against.
    :return: tuple of (recall, precision, f1-score, and jaccard similarity)
    
Compute  the recall, precision, f1-score and jaccard similarity.
Compute the recall precision f1 - score and jaccard similarity .
def similarity_matrices(found_list, ground_list):
    gsets = [set(g) for g in ground_list]
    glens = np.array([float(len(g)) for g in ground_list])
    flens = np.matrix([float(len(f)) for f in found_list])
    flens = np.array(np.tile(flens.transpose(), len(ground_list)))
    logging.info('calculating true positive values')
    tp_mat = np.zeros((len(found_list), len(ground_list)))
    for i, found in enumerate(found_list):
        tp_mat[i] = [len(ground.intersection(found)) for ground in gsets]
    logging.info('calculating found/ground set union sizes')
    union_mat = np.zeros((len(found_list), len(ground_list)))
    for i, found in enumerate(found_list):
        union_mat[i] = [len(ground.union(found)) for ground in gsets]
    logging.info('calculating recall matrix')
    recall = tp_mat / glens
    logging.info('calculating precision matrix')
    precision = tp_mat / flens
    logging.info('calculating f1-score matrix')
    f1 = 2 * recall * precision / (recall + precision)
    f1[np.isnan(f1)] = 0.0  
    logging.info('calculating jaccard coefficient matrix')
    jaccard = tp_mat / union_mat
    return (recall, precision, f1, jaccard)
def similarity_matrices ( found_list , ground_list ) : gsets = [ set ( g ) for g in ground_list ] glens = np . array ( [ float ( len ( g ) ) for g in ground_list ] ) flens = np . matrix ( [ float ( len ( f ) ) for f in found_list ] ) flens = np . array ( np . tile ( flens . transpose ( ) , len ( ground_list ) ) ) logging . info ( 'calculating true positive values' ) tp_mat = np . zeros ( ( len ( found_list ) , len ( ground_list ) ) ) for i , found in enumerate ( found_list ) : tp_mat [ i ] = [ len ( ground . intersection ( found ) ) for ground in gsets ] logging . info ( 'calculating found/ground set union sizes' ) union_mat = np . zeros ( ( len ( found_list ) , len ( ground_list ) ) ) for i , found in enumerate ( found_list ) : union_mat [ i ] = [ len ( ground . union ( found ) ) for ground in gsets ] logging . info ( 'calculating recall matrix' ) recall = tp_mat / glens logging . info ( 'calculating precision matrix' ) precision = tp_mat / flens logging . info ( 'calculating f1-score matrix' ) f1 = 2 * recall * precision / ( recall + precision ) f1 [ np . isnan ( f1 ) ] = 0.0 logging . info ( 'calculating jaccard coefficient matrix' ) jaccard = tp_mat / union_mat return ( recall , precision , f1 , jaccard )
Compute  the recall, precision, f1-score and jaccard similarity.
Compute the recall precision f1 - score and jaccard similarity .
"""Compute  the recall, precision, f1-score and jaccard similarity.

    :param list found_list: List of found communities to evaluate.
    :param list ground_list: List of ground truth communities to compare
        against.
    :return: tuple of (recall, precision, f1-score, and jaccard similarity)
    """ # fill NaN values from 0 division
tuple of (recall, precision, f1-score, and jaccard similarity)
tuple of ( recall precision f1 - score and jaccard similarity )
found_list
List of found communities to evaluate.
List of found communities to evaluate .
ground_list
List of ground truth communities to compare
against.
List of ground truth communities to compare against .