Exemplo n.º 1
0
def _recommendations(model_id, num_interactions, repos, coo, result, name):
    """
    :param repos: List of repository IDs to generate recommendations for.
    :param coo: Co-occurrence matrix A'A where A is a user x item matrix.
    :param result: Function taking two repository IDs and returns a score.
    :param name: Name of CSV file to save recommendation results to.
    """
    results = []
    for idx, id1 in enumerate(repos):
        scores = coo[id1][coo[id1] >= 5].index.map(
            lambda id2: [model_id] + result(coo, num_interactions, id1, id2))
        scores = sorted(scores, key=lambda x: x[3], reverse=True)
        # Exclude first result (since it will be id1)
        results += scores[1:101]
        if idx > 0 and idx % 100 == 0:
            log.debug("Finished {}".format(idx))
    save_csv(name, results)