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

    https://github.com/apache/spark/pull/2378#discussion_r17693196
  
    --- 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 --
    
    Concerning DecisionTree, this is something to be tested and possibly fixed. 
 I suspect it will be better to cache, but need to test.  Some tests do show 
that the final read and persist take much longer than the initial reads, so 
caching will not help.  But other tests indicate it may be worthwhile.  I think 
it is data-dependent, as suggested above.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to