Slide 28
Slide 28 text
val ratings = data.map(_.split("\\s+") match {
case Array(user, item, rate) =>
Rating(user.toInt, item.toInt, rate.toDouble)
})
val splits = ratings.randomSplit(Array(0.8, 0.2))
val training = splits(0).cache()
val test = splits(1)
val model = ALS.train(training, rank = 10, iterations = 20, 0.01)
val userMovies = test.map {
case Rating(user, movie, rate) => (user, movie)
}
val predictions = model.predict(userMovies).map {
case Rating(user, movie, rate) => ((user, movie), rate)
}
training test
model
input data
validation
https://github.com/nivdul/spark-ml-scalaio