【问题标题】:Parallelize a collection with Spark使用 Spark 并行化集合
【发布时间】:2015-05-24 16:07:53
【问题描述】:

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

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

我正在根据记录创建LabeledPoints 列表,每个记录都包含数据点 (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)

那么关于如何让它发挥作用有什么想法吗?

【问题讨论】:

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


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-19
      • 1970-01-01
      • 2019-10-14
      • 2014-02-18
      • 1970-01-01
      • 2012-11-29
      • 1970-01-01
      相关资源
      最近更新 更多