使用Spark并行化集合

时间:2015-03-21 07:18:56

标签: java apache-spark machine-learning artificial-intelligence apache-spark-mllib

我尝试使用Spark并行化集合,文档中的示例似乎不起作用:

List<Integer> data = Arrays.asList(1, 2, 3, 4, 5);
JavaRDD<Integer> distData = sc.parallelize(data);

我在记录中创建LabeledPoint列表,每个记录包含数据点(double[])和标签(默认值:true / false)。

 public List<LabeledPoint> createLabeledPoints(List<ESRecord> records) {
    List<LabeledPoint> points = new ArrayList<>();

    for (ESRecord rec : records) {

        points.add(new LabeledPoint(
                rec.defaulted ? 1.0 : 0.0, Vectors.dense(rec.toDataPoints())));
    }
    return points;
}

public void test(List<ESRecord> records) {
    SparkConf conf = new SparkConf().setAppName("SVM Classifier Example");
    SparkContext sc = new SparkContext(conf);
    List<LabeledPoint> points = createLabeledPoints(records);        
    JavaRDD<LabeledPoint> data = sc.parallelize(points);
    ...
 }

parallelize的函数签名不再是一个参数,这是它在spark-mllib_2.11 v1.3.0中的样子:sc.parallelize(seq, numSlices, evidence$1)

关于如何使这个工作的任何想法?

1 个答案:

答案 0 :(得分:8)