Fitting a linear regression line to data the old fashioned way
In this recipe, we use RDDs and a closed form to code a simple linear equation from scratch. The reason we use this as the first recipe is to demonstrate that you can always implement any given statistical learning algorithm via the RDDs to achieve computational scale using Apache Spark.
How to do it...
- 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.chapter5
- Import the necessary packages for
SparkSession
to gain access to the cluster andlog4j.Logger
to reduce the amount of output produced by Spark:
import org.apache.spark.sql.SparkSession import scala.math._ import org.apache.log4j.Logger import org.apache.log4j.Level
- Initialize a
SparkSession
specifying configurations with the builder pattern thus making an entry point available for the Spark cluster:
val spark = SparkSession .builder...