-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.gradle
145 lines (124 loc) · 4.17 KB
/
build.gradle
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* This file may be freely modified, used, and redistributed without restriction. */
/* Set up the repositories to get the LensKit plugin.
* This configuration pulls in things needed for the build.gradle script itself */
buildscript {
repositories {
// allow maven local to be turned on
if ((project.findProperty('maven.useLocal') ?: 'no') == 'yes') {
mavenLocal()
}
// LensKit snapshots are published to the Sonatype snapshot repository
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
// LensKit releases are published to Maven Central
mavenCentral()
}
dependencies {
classpath "org.lenskit:lenskit-gradle:${project.findProperty('lenskit.version') ?: '3.0-M2'}"
}
}
apply plugin: 'java' // if you use Groovy or Scala, add those plugins
apply plugin: 'lenskit'
/* Set up the repositories for getting LensKit and other libraries.
* These repositories are used for your Java or Groovy code, and for running LensKit.
*/
repositories {
// allow maven local to be turned on
if ((project.findProperty('maven.useLocal') ?: 'no') == 'yes') {
mavenLocal()
}
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
mavenCentral()
}
dependencies {
// Code needs to build with LensKit.
compile "org.lenskit:lenskit-all:${project.findProperty('lenskit.version') ?: '3.0-M2'}"
// To run the code, we also need the LensKit CLI.
runtime "org.lenskit:lenskit-cli:${project.findProperty('lenskit.version') ?: '3.0-M2'}"
// Tests use JUnit
testCompile "junit:junit:4.12"
}
/* Configure LensKit */
lenskit {
// you can configure the threadCount and maxMemory here, or on the command line
// e.g. -PthreadCount=8
}
import org.lenskit.gradle.*
/* Download the MovieLens data set */
task fetchData {
description 'Fetches the MovieLens data set.'
ext.dataDir = "data/ml-100k"
ext.zipFile = "data/ml-100k.zip"
outputs.dir dataDir
outputs.file zipFile
doLast {
mkdir dataDir
ant {
get(src: 'http://files.grouplens.org/datasets/movielens/ml-100k.zip',
dest: zipFile,
skipExisting: true)
unzip(src: zipFile, dest: dataDir) {
patternset {
include name: 'ml-100k/*'
}
mapper type: 'flatten'
}
}
}
}
task crossfold(type: Crossfold, group: 'evaluate') {
// download data before evaluating
dependsOn fetchData
input 'data/ml-100k.yml'
// test on random 1/5 of each user's ratings
holdoutFraction(0.2, 'random')
// use 5-fold cross-validation
partitionCount 5
}
/* Run the LensKit evaluation */
task evaluate(type: TrainTest, group: 'evaluate') {
description 'Runs the LensKit evaluation.'
logFile "$buildDir/evaluate.log"
logFileLevel 'DEBUG'
// we add our crossfold task as evaluation input
dataSet crossfold
// send the output to appropriate files
outputFile "$buildDir/eval-results.csv"
userOutputFile "$buildDir/eval-users.csv"
// configure our algorithms
algorithm 'PersMean', 'algorithms/pers-mean.groovy'
algorithm 'ItemItem', 'algorithms/item-item.groovy'
algorithm 'Custom', 'algorithms/custom.groovy'
// and some evaluation tasks and metrics
predict {
metric 'rmse'
metric 'ndcg'
}
recommend {
listSize 10
metric 'mrr'
}
}
task analyzeResults(type: Exec, group: 'evaluate') {
description 'Post-processes evaluation results to draw charts.'
dependsOn evaluate
inputs.files "$buildDir/eval-results.csv", 'analyze-output.ipynb'
outputs.file "$buildDir/analysis.html"
/* run Jupyter/IPython. Location can be overridden with -Pipython.bin=/usr/bin/ipython */
if (project.hasProperty('ipython.bin')) {
executable project.getProperty('ipython.bin')
} else {
executable 'jupyter'
}
args 'nbconvert', '--to', 'html', '--execute'
args '--output', file("$buildDir/analysis.html")
args file("analyze-output.ipynb")
}
task cleanData {
doLast {
delete 'data'
}
}