Book Image

Scala for Machine Learning, Second Edition - Second Edition

Book Image

Scala for Machine Learning, Second Edition - Second Edition

Overview of this book

The discovery of information through data clustering and classification is becoming a key differentiator for competitive organizations. Machine learning applications are everywhere, from self-driving cars, engineering design, logistics, manufacturing, and trading strategies, to detection of genetic anomalies. The book is your one stop guide that introduces you to the functional capabilities of the Scala programming language that are critical to the creation of machine learning algorithms such as dependency injection and implicits. You start by learning data preprocessing and filtering techniques. Following this, you'll move on to unsupervised learning techniques such as clustering and dimension reduction, followed by probabilistic graphical models such as Naïve Bayes, hidden Markov models and Monte Carlo inference. Further, it covers the discriminative algorithms such as linear, logistic regression with regularization, kernelization, support vector machines, neural networks, and deep learning. You’ll move on to evolutionary computing, multibandit algorithms, and reinforcement learning. Finally, the book includes a comprehensive overview of parallel computing in Scala and Akka followed by a description of Apache Spark and its ML library. With updated codes based on the latest version of Scala and comprehensive examples, this book will ensure that you have more than just a solid fundamental knowledge in machine learning with Scala.
Table of Contents (27 chapters)
Scala for Machine Learning Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface
Index

Time series in Scala


The majority of examples used to illustrate the different machine algorithms in the book deal with time series or sequential, time-ordered sets of observations.

Context bounds

The algorithms presented in this chapter are applied to time series with a single variable of type Double. Therefore we need a mechanism to convert implicitly a given type T to a Double. Scala provides developers with such design: context bounds [3:1]:

  trait ToDouble[T] { def apply(t: T): Double }
  implicit val str2Double = new ToDouble[String] {
     def apply(s: String): Double = s.toDouble
  }

Types and operations

The Defining primitives types section under Source code in Chapter 1, Getting Started introduced the types for time series of single variable, Vector[T], and multiple variables, Vector[Array[T]].

A time series of observations is a vector (type Vector) of observation elements:

  • Of type T in the case of a single-variable/feature observation

  • Of type Array[T] for observations with more than...