Github user staple commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2378#discussion_r17687682
  
    --- Diff: python/pyspark/mllib/recommendation.py ---
    @@ -54,34 +64,51 @@ def __del__(self):
         def predict(self, user, product):
             return self._java_model.predict(user, product)
     
    -    def predictAll(self, usersProducts):
    -        usersProductsJRDD = _get_unmangled_rdd(usersProducts, 
_serialize_tuple)
    -        return RDD(self._java_model.predict(usersProductsJRDD._jrdd),
    -                   self._context, RatingDeserializer())
    +    def predictAll(self, user_product):
    +        assert isinstance(user_product, RDD), "user_product should be RDD 
of (user, product)"
    +        sc = self._context
    +        tuplerdd = 
sc._jvm.SerDe.asTupleRDD(user_product._to_java_object_rdd().rdd())
    +        jresult = self._java_model.predict(tuplerdd).toJavaRDD()
    +        return RDD(sc._jvm.PythonRDD.javaToPython(jresult), sc,
    +                   AutoBatchedSerializer(PickleSerializer()))
     
     
     class ALS(object):
     
         @classmethod
    +    def _prepare(cls, ratings):
    +        assert isinstance(ratings, RDD), "ratings should be RDD"
    +        first = ratings.first()
    +        if not isinstance(first, Rating):
    +            if isinstance(first, (tuple, list)):
    +                ratings = ratings.map(lambda x: Rating(*x))
    +            else:
    +                raise ValueError("rating should be RDD of Rating or 
tuple/list")
    +        # serialize them by AutoBatchedSerializer before cache to reduce 
the
    +        # objects overhead in JVM
    +        cached = 
ratings._reserialize(AutoBatchedSerializer(PickleSerializer())).cache()
    --- End diff --
    
    FWIW it looks like the DecisionTree learner can do multiple reads (of 
varying types) of its input. In DecisionTree.train, 
DecisionTreeMetadata.buildMetadata does a count() on the input, 
DecisionTree.findSplitsBins can do a sampled read, and then 
TreePoint.convertToTreeRDD will do a mapped read that gets persisted. I'm not 
knowledgable enough to know how expensive that initial count() will be without 
further investigation. But I think for DecisionTree the suggestion was not to 
cache before learning.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to