Book Image

Machine Learning with Spark - Second Edition

By : Rajdeep Dua, Manpreet Singh Ghotra
Book Image

Machine Learning with Spark - Second Edition

By: Rajdeep Dua, Manpreet Singh Ghotra

Overview of this book

This book will teach you about popular machine learning algorithms and their implementation. You will learn how various machine learning concepts are implemented in the context of Spark ML. You will start by installing Spark in a single and multinode cluster. Next you'll see how to execute Scala and Python based programs for Spark ML. Then we will take a few datasets and go deeper into clustering, classification, and regression. Toward the end, we will also cover text processing using Spark ML. Once you have learned the concepts, they can be applied to implement algorithms in either green-field implementations or to migrate existing systems to this new platform. You can migrate from Mahout or Scikit to use Spark ML. By the end of this book, you will acquire the skills to leverage Spark's features to create your own scalable machine learning applications and power a modern data-driven business.
Table of Contents (13 chapters)

Plotting

In this segment, we will see how to use Breeze to create a simple line plot from the Breeze DenseVector.

Breeze uses most of the functionality of Scala's plotting facilities, although the API is different. In the following example, we create two vectors x1 and y with some values, and plot a line and save it to a PNG file:

package linalg.plot 
import breeze.linalg._
import breeze.plot._

object BreezePlotSampleOne {
def main(args: Array[String]): Unit = {

val f = Figure()
val p = f.subplot(0)
val x = DenseVector(0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8)
val y = DenseVector(1.1, 2.1, 0.5, 1.0,3.0, 1.1, 0.0, 0.5,2.5)
p += plot(x, y)
p.xlabel = "x axis"
p.ylabel = "y axis"
f.saveas("lines-graph.png")
}
}

The preceding code generates the following Line Plot:

Breeze also supports histogram. This is drawn for various sample sizes 100,000, and...