Book Image

PySpark Cookbook

By : Denny Lee, Tomasz Drabas
Book Image

PySpark Cookbook

By: Denny Lee, Tomasz Drabas

Overview of this book

Apache Spark is an open source framework for efficient cluster computing with a strong interface for data parallelism and fault tolerance. The PySpark Cookbook presents effective and time-saving recipes for leveraging the power of Python and putting it to use in the Spark ecosystem. You’ll start by learning the Apache Spark architecture and how to set up a Python environment for Spark. You’ll then get familiar with the modules available in PySpark and start using them effortlessly. In addition to this, you’ll discover how to abstract data with RDDs and DataFrames, and understand the streaming capabilities of PySpark. You’ll then move on to using ML and MLlib in order to solve any problems related to the machine learning capabilities of PySpark and use GraphFrames to solve graph-processing problems. Finally, you will explore how to deploy your applications to the cloud using the spark-submit command. By the end of this book, you will be able to use the Python API for Apache Spark to solve any problems associated with building data-intensive applications.
Table of Contents (13 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Introducing Transformers


The Transformer class, introduced in Spark 1.3, transforms one dataset into another by normally appending one or more columns to the existing DataFrame. Transformers are an abstraction around methods that actually transform features; the abstraction also includes trained machine learning models (as we will see in the following recipes).

In this recipe, we will introduce two Transformers: Bucketizer and VectorAssembler.

Note

We will not be introducing all the Transformers; throughout the rest of this chapter, the most useful ones will show up. For the rest, the Spark documentation is a good place to learn what they do and how to use them.

Here is a list of all of the Transformers that convert one feature into another:

  • Binarizer is a method that, given a threshold, transforms a continuous numerical feature into a binary one.
  • Bucketizer, similarly to Binarizer, uses a list of thresholds to transform a continuous numerical variable into a discrete one (with as many levels...