so constructing recommedation model using als package , make user-product list cartesian product. , predict ratings. want group ratings users. , final format used (user, (product, ratings)) , have sort decending order.
this code
val ratings = sc.textfile(new file("/user/ubuntu/kang/0829/rawratings.csv").tostring).map { line => val fields = line.split(",") (rating(fields(0).toint,fields(1).toint,fields(2).todouble))} val model = als.train(ratings,10,10,0.1) val numusers = ratings.map(_.user).distinct val nummovies = ratings.map(_.product).distinct val usersproducts = numusers.cartesian(nummovies) val recommendations = model.predict(usersproducts)
but in here value recommendations not pair-rdd , it's rating(_)format cannot apply groupbykey...
could solve problem...?
it's quite simple:
recommendations.map (x => (x.user, (x.product, x.rating))).reducebykey(here put reduce function)
Comments
Post a Comment