metrics.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:skggm 作者: skggm 项目源码 文件源码
def _nonzero_intersection(m, m_hat):
    '''Count the number of nonzeros in and between m and m_hat.

    Returns
    ----------
    m_nnz :  number of nonzeros in m (w/o diagonal)

    m_hat_nnz : number of nonzeros in m_hat (w/o diagonal)

    intersection_nnz : number of nonzeros in intersection of m/m_hat
                      (w/o diagonal)
    '''
    n_features, _ = m.shape

    m_no_diag = m.copy()
    m_no_diag[np.diag_indices(n_features)] = 0
    m_hat_no_diag = m_hat.copy()
    m_hat_no_diag[np.diag_indices(n_features)] = 0

    m_hat_nnz = len(np.nonzero(m_hat_no_diag.flat)[0])
    m_nnz = len(np.nonzero(m_no_diag.flat)[0])

    intersection_nnz = len(np.intersect1d(
        np.nonzero(m_no_diag.flat)[0],
        np.nonzero(m_hat_no_diag.flat)[0]
    ))

    return m_nnz, m_hat_nnz, intersection_nnz
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号