Wisely, is mapToPair in Spark 0.9.1 or 1.0? I'm running the former and didn't see that method available.
I think the issue is that predict() is expecting an RDD containing a tuple of ints and not Integers. So if I use JavaPairRDD<Object,Object> with my original code snippet, things seem to at least compile for now. On Tue, May 27, 2014 at 6:40 PM, giive chen <thegi...@gmail.com> wrote: > Hi Sandeep > > I think you should use testRatings.mapToPair instead of > testRatings.map. > > So the code should be > > > JavaPairRDD<Integer,Integer> usersProducts = training.mapToPair( > new PairFunction<Rating, Integer, Integer>() { > public Tuple2<Integer, Integer> call(Rating r) throws > Exception { > return new Tuple2<Integer, Integer>(r.user(), > r.product()); > } > } > ); > > It works on my side. > > > Wisely Chen > > > On Wed, May 28, 2014 at 6:27 AM, Sandeep Parikh > <sand...@clusterbeep.org>wrote: > >> I've got a trained MatrixFactorizationModel via ALS.train(...) and now >> I'm trying to use it to predict some ratings like so: >> >> JavaRDD<Rating> predictions = model.predict(usersProducts.rdd()) >> >> Where usersProducts is built from an existing Ratings dataset like so: >> >> JavaPairRDD<Integer,Integer> usersProducts = testRatings.map( >> new PairFunction<Rating, Integer, Integer>() { >> public Tuple2<Integer, Integer> call(Rating r) throws Exception { >> return new Tuple2<Integer, Integer>(r.user(), r.product()); >> } >> } >> ); >> >> The problem is that model.predict(...) doesn't like usersProducts, >> claiming that the method doesn't accept an RDD of type Tuple2 however the >> docs show the method signature as follows: >> >> def predict(usersProducts: RDD[(Int, Int)]): RDD[Rating] >> >> Am I missing something? The JavaRDD is just a list of Tuple2 elements, >> which would match the method signature but the compile is complaining. >> >> Thanks! >> >> >