com.datastax.insight.ml.spark.mllib.evaluator.RankingMetricsWrapper Maven / Gradle / Ivy
The newest version!
package com.datastax.insight.ml.spark.mllib.evaluator;
import com.alibaba.fastjson.JSON;
import com.datastax.insight.core.entity.Metrics;
import com.datastax.insight.spec.RDDOperator;
import com.datastax.insight.core.service.PersistService;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.function.Function;
import org.apache.spark.mllib.evaluation.RankingMetrics;
import org.apache.spark.mllib.recommendation.MatrixFactorizationModel;
import org.apache.spark.mllib.recommendation.Rating;
import scala.Tuple2;
import java.util.ArrayList;
import java.util.List;
/**
* Created by huangping on 17-1-16.
*/
public class RankingMetricsWrapper implements RDDOperator {
public Metrics evaluation(MatrixFactorizationModel model, JavaRDD data) {
//get top 10 recommendations for every user and scala ratings from 0 to 1
JavaRDD> userRecs = model.recommendProductsForUsers(10).toJavaRDD();
JavaRDD> userRecsScaled = userRecs.map((Function, Tuple2
© 2015 - 2025 Weber Informatics LLC | Privacy Policy