
Evaluating the model
Since it's a binary classification problem, we need the BinaryClassificationEvaluator() estimator to evaluate the model's performance on the test set:
val evaluator = new BinaryClassificationEvaluator()
.setLabelCol("label")
Now that the training is completed and we have a trained decision tree model, we can evaluate the trained model on the test set:
val predictionDF = dtModel.transform(testDF)
Finally, we compute the classification accuracy:
val accuracy = evaluator.evaluate(predictionDF)
println("Accuracy = " + accuracy)
You should experience about 96% classification accuracy:
Accuracy = 0.9675436785432
Finally, we stop the SparkSession by invoking the stop() method:
spark.stop()
We have managed to achieve about 96% accuracy with minimum effort. However, there are other performance metrics such as precision, recall, and F1 measure. We will discuss them in upcoming chapters. Also, if you're a newbie to ML and haven't understood all the steps in this example, don't worry. We'll recap all of these steps in other chapters with various other examples.