I fitted following logistic regression model using spark MLlib
val df = spark.read.option("header","true").option("inferSchema","true").csv("car_milage-6f50d.csv")
val hasher = new FeatureHasher().setInputCols(Array("mpg","displacement","hp","torque")).setOutputCol("features")
val transformed = hasher.transform(df)
val Array(training, test) = transformed.randomSplit(Array(0.8, 0.2))
val lr = new LogisticRegression()
.setFeaturesCol("features")
.setLabelCol("automatic")
.setMaxIter(20)
val paramGrid = new ParamGridBuilder()
.addGrid(lr.regParam, Array(0.1,0.3))
.addGrid(lr.elasticNetParam, Array(0.9,1))
.build()
val cv = new CrossValidator()
.setEstimator(lr)
.setEvaluator(new BinaryClassificationEvaluator())
.setEstimatorParamMaps(paramGrid)
.setNumFolds(10)
.setParallelism(2)
val model = cv.fit(training)
val results = model.transform(test).select("features", "automatic", "prediction")
val predictionAndLabels = results.select("prediction","label").as[(Double, Double)].rdd
At the end i obtained these model evaluation metrics
val mMetrics = new MulticlassMetrics(predictionAndLabels)
mMetrics.confusionMatrix
mMetrics.labels
mMetrics.accuracy
As the file step I need to write these evaluation metrics (mMetrics) into a file (can be a text file of a csv file) . Can anyone help me how to do that ?
I just tried and i couldn't find any write method which associated with these values.
Thank you