How to do it...

  1. Start a new project in IntelliJ or in an IDE of your choice. Make sure the necessary JAR files are included.
  1. Set up the path using the package directive: package spark.ml.cookbook.chapter9.
  1. Import the necessary packages.

The scala.util.control.Breaks will allow us to break out of the program. We use this during the debugging phase only when the program fails to converge or gets stuck in a never ending process (for example, when the step size is too large).

import scala.collection.mutable.ArrayBufferimport scala.util.control.Breaks._
  1. This step defines the actual quadratic function that we are trying to minimize:
def quadratic_function_itself(x:Double):Double = {// the function being differentiated// f(x) = 2x^2 - 8x ...

Get Apache Spark 2.x Machine Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.