0

予測を BinaryClassificationMetrics boject に渡すために LinearRegression モデルにマップしようとしています。

// Make predictions on test documents. cvModel uses the best model found (lrModel).
DataFrame predictions = cvModel.transform(testingFrame);
JavaRDD<Tuple2<Object, Object>> scoreAndLabels = predictions.map(
        new Function<Row, Tuple2<Object, Object>>() {
            @Override
            public Tuple2<Object, Object> call(Row r) {
                Double score = r.getDouble(1);
                return new Tuple2<Object, Object>(score, r.getDouble(0));
            }
        }
);
BinaryClassificationMetrics metrics
        = new BinaryClassificationMetrics(JavaRDD.toRDD(scoreAndLabels));

ただし、 を呼び出すとpredictions.map(...)、次のコンパイル エラーが発生します。

method map in class DataFrame cannot be applied to given types;
  required: Function1<Row,R>,ClassTag<R>
  found: <anonymous Function<Row,Tuple2<Object,Object>>>
  reason: cannot infer type-variable(s) R
    (actual and formal argument lists differ in length)
  where R is a type-variable:
    R extends Object declared in method <R>map(Function1<Row,R>,ClassTag<R>)

予測データフレームのデータをマッピングする方法について何か提案はありますか?

4

1 に答える 1

1

理解した!DataFrame を JavaRDD に変換する必要があり、そこからは簡単でした。

DataFrame predictions = cvModel.transform(testingFrame);
JavaRDD<Tuple2<Object, Object>> scoreAndLabels = predictions.toJavaRDD().map(
        new Function<Row, Tuple2<Object, Object>>() {
            @Override
            public Tuple2<Object, Object> call(Row r) {
                Double score = r.getDouble(4);
                Double label = r.getDouble(1);
                return new Tuple2<Object, Object>(score, label);
            }
        });

BinaryClassificationMetrics metrics
        = new BinaryClassificationMetrics(JavaRDD.toRDD(scoreAndLabels));
于 2015-03-24T00:16:58.977 に答える