spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giive chen <thegi...@gmail.com>
Subject Re: Java RDD structure for Matrix predict?
Date Tue, 27 May 2014 23:40:43 GMT
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 <sandeep@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!
>
>

Mime
View raw message