In this recipe, we will use the breast cancer and use to demonstrate the Decision Tree implantation in Spark. We will use the IG and Gini to show how to use the facilities already provided by Spark to avoid redundant coding. This recipe attempts to fit a single tree using a binary classification to train and predict the label (benign (0.0) and malignant (1.0)) for the dataset.
- Start a new project in IntelliJ or in an IDE of your choice. Make sure the necessary JAR files are included.
- Set up the package location where the program will reside:
package spark.ml.cookbook.chapter10
- Import the necessary packages for the Spark context to get access to the cluster and
Log4j.Logger
to reduce the amount of output produced by Spark:
import org.apache.spark.mllib.evaluation.MulticlassMetrics import org.apache.spark.mllib.tree.DecisionTree import org.apache.spark.mllib.linalg.Vectors import org.apache.spark.mllib.regression.LabeledPoint...