コード例 #1
0
ファイル: main.py プロジェクト: liheyong/heyong

def evaluation(model, helper, testRatings, testNegatives, K, type_m):
    model.eval()
    (hits, ndcgs) = helper.evaluate_model(model, testRatings, testNegatives, K,
                                          type_m)
    hr, ndcg = np.array(hits).mean(), np.array(ndcgs).mean()
    return hr, ndcg


if __name__ == '__main__':
    # 初始化参数
    config = Config()

    # 初始化工具函数
    helper = Helper()

    # get the dict of follow in user
    u_f_d = helper.gen_user_follow_dict(config.follow_in_user_path2)
    # 加载群组内的用户,构成dict
    # {groupid: [uid1, uid2, ..], ...} 组用户数据
    g_m_d = helper.gen_group_member_dict(config.user_in_group_path2)

    # 初始化数据类 在这里可以决定使用哪个数据
    dataset = GDataset(config.user_dataset2, config.group_dataset2,
                       config.num_negatives)

    # 获取群组的数目、训练集中用户的数目、训练集中物品的数目
    num_group = len(g_m_d)
    num_users, num_items = dataset.num_users, dataset.num_items
    print("num_group is: " + str(num_group))
コード例 #2
0

def evaluation(model, helper, testRatings, testNegatives, K, type_m):
    model.eval()
    (hits, ndcgs) = helper.evaluate_model(model, testRatings, testNegatives, K,
                                          type_m)
    hr, ndcg = np.array(hits).mean(), np.array(ndcgs).mean()
    return hr, ndcg


if __name__ == '__main__':
    # initial parameter class
    config = Config()

    # initial helper
    helper = Helper()

    # get the dict of users in group
    g_m_d = helper.gen_group_member_dict(config.user_in_group_path)

    # initial dataSet class
    dataset = GDataset(config.user_dataset, config.group_dataset,
                       config.num_negatives)

    # get group number~
    num_group = len(g_m_d)
    num_users, num_items = dataset.num_users, dataset.num_items

    # build AGREE model
    agree = AGREE(num_users, num_items, num_group, config.embedding_size,
                  g_m_d, config.drop_ratio)
コード例 #3
0
ファイル: main.py プロジェクト: MinkOrange/MGGCF


def evaluation(model, helper, testRatings, testNegatives, K, type_m):
    model.eval()
    (hits, ndcgs) = helper.evaluate_model(model, testRatings, testNegatives, K, type_m)
    hr, ndcg = np.array(hits).mean(), np.array(ndcgs).mean()
    return hr, ndcg


if __name__ == '__main__':
    # initial parameter class
    config = Config()

    # initial helper
    helper = Helper()


    # initial dataSet class
    dataset = GDataset(config.user_dataset, config.group_dataset,config.num_negatives)

    # get group number
    num_users, num_items, num_groups = dataset.num_users, dataset.num_items, dataset.num_groups

    # build NCF model
    ncf = NCF(num_users, num_items, num_groups, config.factor_num, config.num_layers , config.drop_ratio)

    # config information
    print("NCF at embedding size %d, run Iteration:%d, NDCG and HR at %d" %(config.factor_num, config.epoch, config.topK))
    # train the model
    for epoch in range(config.epoch):