Search code examples
apache-sparkrecommendation-engineapache-spark-mllibcollaborative-filteringmatrix-factorization

MLlib collaborative filtering to generate Top N recommendations


I was looking to find out a way to generate top n recommendations for all users using MLlib's ALS matrix factorization, but remained unsuccessful. Can anybody tell me does any such method exist?


Solution

  • here is my current approach which seems to be extremely slow:

    Iterator<Rating> it = ratings.toLocalIterator();
            while (it.hasNext()) {
                int user = it.next().user();
                if (!userList.contains(user)) {
                    Rating[] rat = model.recommendProducts(user, 10);
                    for (Rating r : rat) {
                        list.add(user + "," + r.product() + "," + r.rating());
                    }
                    userList.add(user);
                }
            }
    

    any efficient approach would be greatly appreciated.