本文整理汇总了Java中org.apache.spark.api.java.JavaPairRDD.fromJavaRDD方法的典型用法代码示例。如果您正苦于以下问题:Java JavaPairRDD.fromJavaRDD方法的具体用法?Java JavaPairRDD.fromJavaRDD怎么用?Java JavaPairRDD.fromJavaRDD使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.spark.api.java.JavaPairRDD
的用法示例。
在下文中一共展示了JavaPairRDD.fromJavaRDD方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getReciprocalMatches
import org.apache.spark.api.java.JavaPairRDD; //导入方法依赖的package包/类
public JavaPairRDD<Integer,Integer> getReciprocalMatches(JavaPairRDD<Integer,Integer> top1Candidates) {
return JavaPairRDD.fromJavaRDD(top1Candidates
.filter(x -> x != null)
.filter(x -> x._1() != null && x._2() != null)
.mapToPair(pair-> {
if (pair._1() < pair._2()) { //put smaller entity id first
return new Tuple2<>(new Tuple2<>(pair._1(), pair._2()),1);
}
return new Tuple2<>(new Tuple2<>(pair._2(), pair._1()),1);
})
.reduceByKey((x,y)->x+y)
.filter(counts->counts._2() == 2) //1 from the first entity + 1 from the second
.keys());
}
示例2: getError
import org.apache.spark.api.java.JavaPairRDD; //导入方法依赖的package包/类
private static Double getError(JavaRDD<Rating> testRdd, int rank, int iterationsNr, JavaRDD<Tuple2<Object, Object>> testForPredict, TimeKeeper timeKeeper, MatrixFactorizationModel model) {
timeKeeper.start();
JavaPairRDD<Tuple2<Integer, Integer>, Double> predictions = JavaPairRDD.fromJavaRDD(
model.predict(testForPredict.rdd())
.toJavaRDD()
.map(r -> new Tuple2<>(new Tuple2<>(r.user(), r.product()), r.rating()))
);
Double error = computeRMSE(predictions, testRdd);
timeKeeper.end().print(logger, "rmse calculated in ").reset();
logger.info(String.format("For rank %d and iterations %d the RMSE is %f", rank, iterationsNr, error));
return error;
}