然后只需
map将RDD(
labelsAndPredictions)的行转换为字符串(CSV的行)即可
rdd.saveAsTextFile()。
def toCSVLine(data): return ','.join(str(d) for d in data)lines = labelsAndPredictions.map(toCSVLine)lines.saveAsTextFile('hdfs://my-node:9000/tmp/labels-and-predictions.csv')


