Skip to content

Commit

Permalink
[SPARK-20553][ML][PYSPARK] Update ALS examples with recommend-all met…
Browse files Browse the repository at this point in the history
…hods

Update ALS examples illustrating use of "recommendForAllX" methods.

## How was this patch tested?
Built and ran examples locally

Author: Nick Pentreath <nickp@za.ibm.com>

Closes #17950 from MLnick/SPARK-20553-update-als-examples.
  • Loading branch information
Nick Pentreath committed May 16, 2017
1 parent dbe8163 commit 6af7b43
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,15 @@ public static void main(String[] args) {
.setPredictionCol("prediction");
Double rmse = evaluator.evaluate(predictions);
System.out.println("Root-mean-square error = " + rmse);

// Generate top 10 movie recommendations for each user
Dataset<Row> userRecs = model.recommendForAllUsers(10);
// Generate top 10 user recommendations for each movie
Dataset<Row> movieRecs = model.recommendForAllItems(10);
// $example off$
userRecs.show();
movieRecs.show();

spark.stop();
}
}
8 changes: 8 additions & 0 deletions examples/src/main/python/ml/als_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,13 @@
predictionCol="prediction")
rmse = evaluator.evaluate(predictions)
print("Root-mean-square error = " + str(rmse))

# Generate top 10 movie recommendations for each user
userRecs = model.recommendForAllUsers(10)
# Generate top 10 user recommendations for each movie
movieRecs = model.recommendForAllItems(10)
# $example off$
userRecs.show()
movieRecs.show()

spark.stop()
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ object ALSExample {
.setPredictionCol("prediction")
val rmse = evaluator.evaluate(predictions)
println(s"Root-mean-square error = $rmse")

// Generate top 10 movie recommendations for each user
val userRecs = model.recommendForAllUsers(10)
// Generate top 10 user recommendations for each movie
val movieRecs = model.recommendForAllItems(10)
// $example off$
userRecs.show()
movieRecs.show()

spark.stop()
}
Expand Down

0 comments on commit 6af7b43

Please sign in to comment.