예제 #1
0
    prec, recall, _ = precision_recall_curve(GROUND_TRUTH[target_idx],
                                             P[target_idx])
    return auc(recall, prec)


if __name__ == '__main__':
    # load data
    st = dt.datetime.now()
    mat = loadmat('E:/experiments/rescal-bilinear/data/countries_s2.mat')
    #mat = loadmat('F:/experiment/rescal-bilinear/data/umls.mat')
    #mat = loadmat('F:/experiment/rescal-bilinear/data/nations.mat')
    K = array(mat['Rs'], np.float32)
    #print(K[0],K.shape)
    K = Tensor2Matrix(K)
    #print(K[0],'\r',K.shape)
    K = HimmingDistance(K, -0.0005)
    #print(K)

    e, k = K.shape[0], K.shape[2]
    SZ = e * e * k
    # copy ground truth before preprocessing
    GROUND_TRUTH = K.copy()

    # construct array for rescal
    T = [lil_matrix(K[:, :, i]) for i in range(k)]

    _log.info('Datasize: %d x %d x %d | No. of classes: %d' %
              (T[0].shape + (len(T), ) + (k, )))

    # Do cross-validation
    FOLDS = 10
예제 #2
0
                                             P[target_idx])
    ac = accuracy_score(GROUND_TRUTH[target_idx], P[target_idx].round())
    return auc(recall, prec), ac


if __name__ == '__main__':
    # load data
    #st = dt.datetime.now()
    #mat = loadmat('F:/experiment/rescal-bilinear/data/alyawarradata.mat')
    #mat = loadmat('E:/experiments/rescal-bilinear/data/alyawarradata.mat')
    mat = loadmat('E:/experiments/rescal-bilinear/data/dnations.mat')
    K = array(mat['R'], np.float32)
    #print(K[0],K.shape)
    K = Tensor2Matrix(K)
    #print(K[0],'\r',K.shape)
    K = HimmingDistance(K, 0.00000004)
    #print(K)
    st = dt.datetime.now()
    e, k = K.shape[0], K.shape[2]
    SZ = e * e * k
    # copy ground truth before preprocessing
    GROUND_TRUTH = K.copy()

    # construct array for rescal
    T = [lil_matrix(K[:, :, i]) for i in range(k)]

    _log.info('Datasize: %d x %d x %d | No. of classes: %d' %
              (T[0].shape + (len(T), ) + (k, )))

    # Do cross-validation
    FOLDS = 10