-
Notifications
You must be signed in to change notification settings - Fork 1
/
recommend.r
executable file
·61 lines (47 loc) · 2.41 KB
/
recommend.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env Rscript
# Error handling
options(error = function() {
traceback(2)
if (!interactive()) quit("no", status = 1, runLast = FALSE)
})
suppressPackageStartupMessages(library("methods"))
suppressPackageStartupMessages(library("argparse"))
suppressPackageStartupMessages(library("recommenderlab"))
suppressPackageStartupMessages(library("data.table"))
suppressPackageStartupMessages(library("futile.logger"))
source("utils.r")
if (!interactive()) {
# create parser object
parser <- ArgumentParser()
parser$add_argument("input", help = "Print extra output [default]")
parser$add_argument("min_users", type = "integer", help = "minimum number of users")
parser$add_argument("min_recipes", type = "integer", help = "minimum number of recipes")
parser$add_argument("size", type = "integer", help = "sample size")
# parse command-line arguments
args <- parser$parse_args()
} else {
args = list(input = '/Users/benny/Repositories/recipes/data/reviews.csv',
min_users = 10,
min_recipes = 10,
size = 100)
}
flog.info("Loading rating data from input...")
RecipeRatings <- loadData(args$input)
RecipeRatings <- selectRows(RecipeRatings, args$min_users, args$min_recipes)
#RecipeRatings <- RecipeRatings[1:args$size]
flog.info("Finished loading rating data.")
dim(RecipeRatings)
# Algorithms to use
algorithms <- list("random items" = list(name = "RANDOM", param = NULL),
"popular items" = list(name = "POPULAR", param = NULL),
"item-based CF (Jaccard, nn = 10)" = list(name = "IBCF", param = list(nn = 10, method = 'jaccard')),
"item-based CF (Jaccard, nn = 20)" = list(name = "IBCF", param = list(nn = 20, method = 'jaccard')),
"item-based CF (Jaccard, nn = 30)" = list(name = "IBCF", param = list(nn = 30, method = 'jaccard')),
"item-based CF (Pearson, nn = 10)" = list(name = "IBCF", param = list(nn = 10, method = 'pearson')),
"item-based CF (Pearson, nn = 20)" = list(name = "IBCF", param = list(nn = 20, method = 'pearson')),
"item-based CF (Pearson, nn = 30)" = list(name = "IBCF", param = list(nn = 30, method = 'pearson')))
scheme <- evaluationScheme(RecipeRatings, method="split", train = .9,
k = 1, given = -5, goodRating = 5)
results <- evaluate(scheme, algorithms, type = "ratings")
results
save.image('recommend.RData')