unicode_literals) from amaze import Dataset from amaze import SVD from amaze import accuracy from amaze.model_selection import KFold data = Dataset.load_builtin('ml-100k') algo = SVD() trainset = data.build_full_trainset() algo.fit(trainset) testset = trainset.build_testset() predictions = algo.test(testset) # RMSE should be low as we are biased accuracy.rmse(predictions, verbose=True) # ~ 0.68 (which is low) # We can also do this during a cross-validation procedure! print('CV procedure:') kf = KFold(n_splits=3) for i, (trainset_cv, testset_cv) in enumerate(kf.split(data)): print('fold number', i + 1) algo.fit(trainset_cv) print('On testset,', end=' ') predictions = algo.test(testset_cv) accuracy.rmse(predictions, verbose=True)
""" This module describes how to use the train_test_split() function. """ from __future__ import (absolute_import, division, print_function, unicode_literals) from amaze import SVD from amaze import Dataset from amaze import accuracy from amaze.model_selection import train_test_split # Load the movielens-100k dataset (download it if needed), data = Dataset.load_builtin('ml-100k') # sample random trainset and testset # test set is made of 25% of the ratings. trainset, testset = train_test_split(data, test_size=.25) # We'll use the famous SVD algorithm. algo = SVD() # Train the algorithm on the trainset, and predict ratings for the testset algo.fit(trainset) predictions = algo.test(testset) # Then compute RMSE accuracy.rmse(predictions)
algorithm. The SVD algorithm is trained on a dataset and then serialized. It is then reloaded and can be used again for making predictions. """ from __future__ import (absolute_import, division, print_function, unicode_literals) import os from amaze import SVD from amaze import Dataset from amaze import dump data = Dataset.load_builtin('ml-100k') trainset = data.build_full_trainset() algo = SVD() algo.fit(trainset) # Compute predictions of the 'original' algorithm. predictions = algo.test(trainset.build_testset()) # Dump algorithm and reload it. file_name = os.path.expanduser('~/dump_file') dump.dump(file_name, algo=algo) _, loaded_algo = dump.load(file_name) # We now ensure that the algo is still the same by checking the predictions. predictions_loaded_algo = loaded_algo.test(trainset.build_testset()) assert predictions == predictions_loaded_algo print('Predictions are the same')