Last active
February 17, 2017 08:17
-
-
Save sarmadsaleem/e3d4dda50a69f5e8c9aa327d57554af1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
algorithm recommender_algorithm_ALS is | |
input: my_ratings.txt | |
output: recommendations.txt | |
// 1. Load & Parse Data | |
my_ratings = rdd(parse(path/to/my_ratings)) | |
ratings = rdd(parse(path/to/small-ratings.csv)) | |
movies = rdd(parse(path/to/small-movies.csv)) | |
complete_ratings = rdd(parse(path/to/ratings.csv)) | |
complete_movies = rdd(parse(path/to/movies.csv)) | |
training = ratings.filter() | |
validation = ratings.filter() | |
test = ratings.filter() | |
// 2. Train model & evaluate on validation set | |
seed = 5L | |
iterations = 10 | |
regularization_parameter = 0.1 | |
ranks = [4, 8, 12] | |
errors = [0, 0, 0] | |
err = 0 | |
tolerance = 0.02 | |
for rank in ranks | |
model = ALS.train(training, rank, seed, iterations, regularization_parameter) | |
predictions = model.PredictAll(validation).map() | |
endfor | |
bestRank = bestRank(model) | |
training, test = complete_ratings.randomSplit([7, 3], seed=0L) | |
complete_model = ALS.train(training, bestRank, seeds, iterations, regularization_parameter) | |
predictions = complete_model.PredictAll(test).map() | |
complete_ratings_data = complete_rating.filter().map() | |
complete_data_with_new_ratings = rdd(complete_ratings_data.union(my_ratings)) | |
// 3. Make recommendations | |
new_ratings_model = ALS.train(complete_data_with_new_ratings, best_rank, seed, iterations, regularization_parameter) | |
recommendations = new_ratings_model.predictAll(complete_data_with_new_ratings) | |
log(output, transformResults(recommendations)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment