def testKNNbasic(): for i in range(1,10): print 'k=',i*10 algo=KNNBasic(k=i*10) #algo=SVD() evaluate(algo,data)
from recsys import AlgoBase from recsys import Dataset from recsys import evaluate class MyOwnAlgorithm(AlgoBase): def __init__(self): # Always call base method before doing anything. AlgoBase.__init__(self) def train(self, trainset): # Here again: call base method before doing anything. AlgoBase.train(self, trainset) # Compute the average rating. We might as well use the # trainset.global_mean attribute ;) self.the_mean = np.mean( [r for (_, _, r) in self.trainset.all_ratings()]) def estimate(self, u, i): return self.the_mean data = Dataset.load_builtin('ml-100k') algo = MyOwnAlgorithm() evaluate(algo, data)
""" This module descibes the most basic usage of RecSys: you define a prediction algorithm, (down)load a dataset and evaluate the performances of the algorithm. """ from __future__ import (absolute_import, division, print_function, unicode_literals) from recsys import NormalPredictor from recsys import Dataset from recsys import evaluate # Load the movielens-100k dataset and split it into 3 folds for # cross-validation. data = Dataset.load_builtin('ml-100k') data.split(n_folds=3) # This algorithm predicts a random rating sampled from a normal distribution. algo = NormalPredictor() # Evaluate performances of our algorithm on the dataset. perf = evaluate(algo, data, measures=['RMSE', 'MAE']) print(perf['RMSE']) print(perf['MAE'])