Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cs449 Template M2 2022
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hugo Manuel Serge Lanfranchi
Cs449 Template M2 2022
Commits
b79b8529
Commit
b79b8529
authored
4 years ago
by
Erick Lavoie
Browse files
Options
Downloads
Patches
Plain Diff
Updated README
parent
2a82ef7f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+8
-2
8 additions, 2 deletions
README.md
data/personal.csv
+0
-1
0 additions, 1 deletion
data/personal.csv
src/main/scala/recommend/Recommender.scala
+79
-2
79 additions, 2 deletions
src/main/scala/recommend/Recommender.scala
with
87 additions
and
5 deletions
README.md
+
8
−
2
View file @
b79b8529
...
...
@@ -46,12 +46,18 @@ Do include your own ratings in your final submission so we can check your answer
## Compute predictions
````
> sbt "runMain predict.Predictor --train data/ml-100k/u1.base --test data/ml-100k/u1.test --json answers.json"
> sbt "runMain stats.Analyzer --data data/ml-100k/u.data --json statistics.json"
````
## Compute predictions
````
> sbt "runMain predict.Predictor --train data/ml-100k/u1.base --test data/ml-100k/u1.test --json predictions.json"
````
## Compute recommendations
````
> sbt
'
runMain recommend.Recommender
'
> sbt
"
runMain recommend.Recommender
--data data/ml-100k/u.data --personal data/personal.csv --json recommendations.json"
````
## Package for submission
...
...
This diff is collapsed.
Click to expand it.
data/personal.csv
+
0
−
1
View file @
b79b8529
id,title,
1,Toy Story (1995),
2,GoldenEye (1995),
3,Four Rooms (1995),
...
...
This diff is collapsed.
Click to expand it.
src/main/scala/recommend/Recommender.scala
+
79
−
2
View file @
b79b8529
package
recommend
import
org.rogach.scallop._
import
org.json4s.jackson.Serialization
import
org.apache.spark.rdd.RDD
import
org.apache.spark.sql.SparkSession
import
org.apache.log4j.Logger
import
org.apache.log4j.Level
class
Conf
(
arguments
:
Seq
[
String
])
extends
ScallopConf
(
arguments
)
{
val
data
=
opt
[
String
](
required
=
true
)
val
personal
=
opt
[
String
](
required
=
true
)
val
json
=
opt
[
String
]()
verify
()
}
case
class
Rating
(
user
:
Int
,
item
:
Int
,
rating
:
Double
)
object
Recommender
extends
App
{
println
(
"Computing recommendations ..."
)
println
(
"Done"
)
// Remove these lines if encountering/debugging Spark
Logger
.
getLogger
(
"org"
).
setLevel
(
Level
.
OFF
)
Logger
.
getLogger
(
"akka"
).
setLevel
(
Level
.
OFF
)
val
spark
=
SparkSession
.
builder
()
.
master
(
"local[1]"
)
.
getOrCreate
()
spark
.
sparkContext
.
setLogLevel
(
"ERROR"
)
println
(
""
)
println
(
"******************************************************"
)
var
conf
=
new
Conf
(
args
)
println
(
"Loading data from: "
+
conf
.
data
())
val
dataFile
=
spark
.
sparkContext
.
textFile
(
conf
.
data
())
val
data
=
dataFile
.
map
(
l
=>
{
val
cols
=
l
.
split
(
"\t"
).
map
(
_
.
trim
)
Rating
(
cols
(
0
).
toInt
,
cols
(
1
).
toInt
,
cols
(
2
).
toDouble
)
})
assert
(
data
.
count
==
100000
,
"Invalid data"
)
println
(
"Loading personal data from: "
+
conf
.
personal
())
val
personalFile
=
spark
.
sparkContext
.
textFile
(
conf
.
personal
())
// TODO: Extract ratings and movie titles
assert
(
personalFile
.
count
==
1682
,
"Invalid personal data"
)
// Save answers as JSON
def
printToFile
(
content
:
String
,
location
:
String
=
"./answers.json"
)
=
Some
(
new
java
.
io
.
PrintWriter
(
location
)).
foreach
{
f
=>
try
{
f
.
write
(
content
)
}
finally
{
f
.
close
}
}
conf
.
json
.
toOption
match
{
case
None
=>
;
case
Some
(
jsonFile
)
=>
{
var
json
=
""
;
{
// Limiting the scope of implicit formats with {}
implicit
val
formats
=
org
.
json4s
.
DefaultFormats
val
answers
:
Map
[
String
,
Any
]
=
Map
(
"4.1.1"
->
List
[
Any
](
List
(
0
,
"Tron"
,
5.0
),
List
(
0
,
"Tron"
,
5.0
),
List
(
0
,
"Tron"
,
5.0
),
List
(
0
,
"Tron"
,
5.0
),
List
(
0
,
"Tron"
,
5.0
)
)
)
json
=
Serialization
.
writePretty
(
answers
)
}
println
(
json
)
println
(
"Saving answers in: "
+
jsonFile
)
printToFile
(
json
,
jsonFile
)
}
}
println
(
""
)
spark
.
close
()
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment