0

I've got an array with predictions and labels from logistic regression which looks like this:

labelAndPreds: org.apache.spark.rdd.RDD[(Double, Double)] =  
MapPartitionsRDD[517] at map at <console>:52

scala> labelAndPreds.collect()
res2: Array[(Double, Double)] = Array((0.004106564139257318, 0.0), 
(0.3641478408865635, 0.0), (0.9999258409695498, 1.0), (0.342287288060...

How can I save it on local disk in CSV format with two columns (one for labels and one for predictions)?

1 Answer 1

2

You can use spark-csv :

import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.SQLContext.implicits._

val df = labelsAndPreds.toDF("labels", "predictions")

df.write
    .format("com.databricks.spark.csv")
    .option("header", "true")
    .save("labelsAndPreds.csv")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.