diff --git a/mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala b/mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala index 00fe741383db1..5a01dfcd2baee 100644 --- a/mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala +++ b/mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala @@ -107,7 +107,7 @@ class MatrixFactorizationModel private[mllib] ( scored.top(num)(Ordering.by(_._2)) } - def userFeaturesString(userFeatures: RDD[(Int, Array[Double])]): RDD[String] = { + def userFeaturesString(): RDD[String] = { userFeatures.map(element => element._1+","+element._2.mkString(",")) } } diff --git a/python/pyspark/mllib/recommendation.py b/python/pyspark/mllib/recommendation.py index 59c1c5ff0ced0..2ab4e71534200 100644 --- a/python/pyspark/mllib/recommendation.py +++ b/python/pyspark/mllib/recommendation.py @@ -82,6 +82,11 @@ def predictAll(self, user_product): return RDD(sc._jvm.PythonRDD.javaToPython(jresult), sc, AutoBatchedSerializer(PickleSerializer())) + def userFeatures(self): + sc = self._context + juf = self._java_model.userFeaturesString().toJavaRDD() + return RDD(sc._jvm.PythonRDD.javaToPython(juf), sc, + AutoBatchedSerializer(PickleSerializer())) class ALS(object):