Ejemplo n.º 1
0
def LoadMovieLensData():
    ml = MovieLens()
    print("Loading movie ratings...")
    data = ml.loadMovieLensLatestSmall()
    print(
        "\nComputing movie popularity ranks so we can measure novelty later..."
    )
    rankings = ml.getPopularityRanks()
    return (ml, data, rankings)


np.random.seed(0)
random.seed(0)

# load up common data set for the recommender algorithms
(ml, evaluationData, rankings) = LoadMovieLensData()

# construct an evaluator to
evaluator = Evaluator(evaluationData, rankings)

contentKNN = ContentKNNAlgorithm()
evaluator.addAlgorithm(contentKNN, "ContentKNN")

# just make random recommendations
Random = NormalPredictor()
evaluator.addAlgorithm(Random, "Random")

evaluator.evaluate(False)

evaluator.sampleTopNRecs(ml)