'NormalPredictor': '[{}]({})'.format('Random', stable + 'basic_algorithms.html#amaze.prediction_algorithms.random_pred.NormalPredictor'), 'ml-100k': '[{}]({})'.format('Movielens 100k', 'http://grouplens.org/datasets/movielens/100k'), 'ml-1m': '[{}]({})'.format('Movielens 1M', 'http://grouplens.org/datasets/movielens/1m'), } # set RNG np.random.seed(0) random.seed(0) dataset = 'ml-1m' data = Dataset.load_builtin(dataset) kf = KFold(random_state=0) # folds will be the same for all algorithms. table = [] for klass in classes: start = time.time() out = cross_validate(klass(), data, ['rmse', 'mae'], kf) cv_time = str(datetime.timedelta(seconds=int(time.time() - start))) link = LINK[klass.__name__] mean_rmse = '{:.3f}'.format(np.mean(out['test_rmse'])) mean_mae = '{:.3f}'.format(np.mean(out['test_mae'])) new_line = [link, mean_rmse, mean_mae, cv_time] print(tabulate([new_line], tablefmt="pipe")) # print current algo perf table.append(new_line)
""" This module gives an example of how to configure similarity measures computation. """ from __future__ import (absolute_import, division, print_function, unicode_literals) from amaze import KNNBasic from amaze import Dataset from amaze.model_selection import cross_validate # Load the movielens-100k dataset. data = Dataset.load_builtin('ml-100k') # Example using cosine similarity sim_options = { 'name': 'cosine', 'user_based': False # compute similarities between items } algo = KNNBasic(sim_options=sim_options) cross_validate(algo, data, verbose=True) # Example using pearson_baseline similarity sim_options = { 'name': 'pearson_baseline', 'shrinkage': 0 # no shrinkage } algo = KNNBasic(sim_options=sim_options)