Skip to content

SPARK-2768 [MLLIB] Add product, user recommend method to MatrixFactorizationModel - #1687

Closed
srowen wants to merge 3 commits into
apache:masterfrom
srowen:SPARK-2768
Closed

srowen wants to merge 3 commits into
apache:masterfrom
srowen:SPARK-2768

Conversation

@srowen

@srowen srowen commented Jul 31, 2014

Copy link
Copy Markdown
Member

Right now, MatrixFactorizationModel can only predict a score for one or more (user,product) tuples. As a comment in the file notes, it would be more useful to expose a recommend method, that computes top N scoring products for a user (or vice versa – users for a product).

(This also corrects some long lines in the Java ALS test suite.)

As you can see, it's a little messy to access the class from Java. Should there be a Java-friendly wrapper for it? with a pointer about where that should go, I could add that.

@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

QA tests have started for PR 1687. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17576/consoleFull

@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

QA results for PR 1687:
- This patch PASSES unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17576/consoleFull

@mengxr

mengxr commented Jul 31, 2014

Copy link
Copy Markdown
Contributor

@srowen This is great! I was about to add the same function. We only have RDD.top in core, but if we have PairRDDFunctions.topByKey, we can make recommendation on a small batch of users/products. Another possible optimization is to use more partitions for the final user/product features. Beside some inline comments, could you also set the storage level of the final user/product features to MEMORY_AND_DISK in this PR? We saw use cases where the features were kicked out of memory by later jobs on the same cluster.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommends products to a user.?

@mengxr

mengxr commented Jul 31, 2014

Copy link
Copy Markdown
Contributor

For the API, another option is to return Array[Rating] instead of Array[(Int, Double)]. This should help Java users and it is also compatible with batch predictions if we want to add in the future.

@srowen

srowen commented Jul 31, 2014

Copy link
Copy Markdown
Member Author

Thanks @mengxr I agree with all of that and will update the PR. Rating is a good solution; there's a redundant field but very few objects are returned anyway. Sorry I'm being dense but which RDD should be set to MEMORY_AND_DISK? the scored RDD in my PR? and how would you set partitions?

Yes if there were a topByKey it would be natural to expose a small batch recommend feature here. There are other possible operations here like mostSimilar but we can leave that for another PR after discussing what the metric should be -- cosine similarity? etc.

@mengxr

mengxr commented Jul 31, 2014

Copy link
Copy Markdown
Contributor

I meant the final userFeatures and productFeatures stored in the matrix factorization model. If those two RDDs are kicked out from memory by later jobs, we have to restart from the very beginning. Having more partitions can also help lookup. So I'm thinking about changing

https://github.com/srowen/spark/blob/SPARK-2768/mllib/src/main/scala/org/apache/spark/mllib/recommendation/ALS.scala#L287

to

    usersOut.setName("usersOut").persist(StorageLevel.MEMORY_AND_DISK)
    productsOut.setName("productsOut").persist(StorageLevel.MEMORY_AND_DISK)

and maybe also make them have more partitions in unblockFactors for quick lookup.

@srowen

srowen commented Jul 31, 2014

Copy link
Copy Markdown
Member Author

Cool, I committed some updates to address these points. The change to persistence and partitions is something you want to do separately? Yes I agree these should be cached in memory if possible.

@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

QA tests have started for PR 1687. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17588/consoleFull

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc is no longer accurate because we switched to Array[Rating].

@mengxr

mengxr commented Jul 31, 2014

Copy link
Copy Markdown
Contributor

@srowen For changing the storage level, I can submit another PR after this gets merged and ping you for review.

@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

QA results for PR 1687:
- This patch FAILED unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17588/consoleFull

@SparkQA

SparkQA commented Aug 1, 2014

Copy link
Copy Markdown

QA tests have started for PR 1687. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17672/consoleFull

@SparkQA

SparkQA commented Aug 1, 2014

Copy link
Copy Markdown

QA results for PR 1687:
- This patch PASSES unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17672/consoleFull

@mengxr

mengxr commented Aug 1, 2014

Copy link
Copy Markdown
Contributor

LGTM. Merged into master. Thanks!!

@asfgit asfgit closed this in 82d209d Aug 1, 2014
@srowen
srowen deleted the SPARK-2768 branch August 1, 2014 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants