PySparkling

License

this section provides an introduction to pysparkling. to understand more about pysparkling, it’s better to understand h2o, spark, and sparkling water first.

What is H2O?

h2o is an open-source, in-memory, distributed, fast and scalable machine learning and predictive analytics platform that provides capability to build machine learning models on big data and enable easy productionalization of them in an enterprise environment.

h2o core code is written in java. inside h2o, a distributed key/value (dkv) store is used to access and reference data, models, objects, etc., across all nodes/machines, has a non blocking hashmap and a memory manager. the algoritms are implemented in the map-reduce style and utilize the java fork/join framework.

the data is read in parallel and distributed across the cluster, stored in memory in a columnar format in a compressed way. h2o’s data parser has built-in intelligence to guess the schema of the incoming dataset and supports data ingestion from multiple sources in various formats.

宁夏微乐滑水麻将下载h2o’s rest api enables to access all the capabilities of h2o from an external program or script, via json over http. the rest api is used by h2o’s web interface (flow ui), the r binding (h2o-r) and the python binding (h2o-python).

the speed, quality, ease of use and model deployment, for the various cutting-edge supervised and unsupervised algorithms like deep learning, tree ensembles and generalized low rank models, makes h2o a highly sought after api for big data analytics.

What is Spark?

apache spark is an open-source, in-memory, distributed cluster computing framework that provides a comprehensive capability of building efficient big data pipelines.

宁夏微乐滑水麻将下载spark core implements a distributed memory abstraction, called resilient distributed datasets (rdds) and manages distributed task dispatching and scheduling. rdds represents the first api for transforming data with apache spark and became essential building blocks for higher abstractions like datasets and dataframes (datasets of row objects).

宁夏微乐滑水麻将下载datasets/dataframes in contrast to rdds track the schema of transformed data and offer faster execution in most cases due to the tungsten memory representation and utilization of the catalyst optimizer. furthermore, dataset/dataframe api is very similar sql of standard database engines, thus data engineers and scientists can learn the api very fast.

rdds and datasets/dataframes represents distributed data that sits on disk. any transformation applied on rdds and datasets/dataframes is lazy and nothing is executed until a user calls an action on a given abstraction. rdds and datasets/dataframes can be cashed in order to avoid multiple execution of the same sequence of transformations.

spark provides apis in java, python, scala, and r for building and manipulating rdds and datasets/dataframes. spark also comes with libraries having capabilities to process streamed data, graph data and to apply basic ml algorithms.

宁夏微乐滑水麻将下载the fast and unified framework to manage data processing, makes spark a preferred solution for big data analysis.

What is Sparkling Water?

宁夏微乐滑水麻将下载sparkling water is an integration of h2o into the spark ecosystem. it facilitates the use of h2o algorithms in spark workflows. it is designed as a regular spark application and provides a way to start h2o services on each node of a spark cluster and access data stored in data structures of spark and h2o.

A Spark cluster is composed of one Driver JVM and one or many Executor JVMs. A Spark Context is a connection to a Spark cluster. Each Spark application creates a SparkSession. The machine where the Spark application process, that creates a SparkSession (spark), is running, is the Driver node. The Spark Context connects to the cluster manager (either Spark standalone cluster manager, Mesos or YARN), that allocates executors to spark cluster for the application. Then, Spark sends the application code (defined by JAR or Python files) to the executors. Finally, the Spark Context sends tasks to the executors to run.

The driver program in Sparkling Water, creates a SparkSession (spark) which in turn is used to create an H2OContext宁夏微乐滑水麻将下载 (hc) that is used to start H2O services on the spark executors. An H2O Context is a connection to H2O cluster and also facilitates communication between H2O and Spark. When an H2O cluster starts, it has the same topology as the Spark cluster and H2O nodes shares the same JVMs as the Spark Executors.

to leverage h2o’s algorithms, data in spark cluster, stored as an rdd or dataset/dataframe, needs to be converted to an h2oframe (h2o’s distributed data frame). this requires a data copy because of the difference in data layout in spark (blocks/rows) and h2o (columns). but as data is stored in h2o in a highly compressed format, the overhead of making a data copy is low. when converting an h2oframe to a rdd or dataframe, sparkling water creates a wrapper around the h2oframe to provide a given spark api. in this case, no data is duplicated and data is served directly from the underlying h2oframe. as h2o runs in the same jvms as the spark executors, moving data from spark to h2o or vice-versa requires a simple in memory, in process call.

What is PySparkling?

pysparkling is an integration of python with sparkling water. it allows user to start h2o services on a spark cluster from python api.

in the pysparkling driver program, the spark context, which uses py4j to start the driver jvm and the java spark context, is used to create the h2o context (hc). that in turn starts an h2o cloud (cluster) in the spark ecosystem. once the h2o cluster is up, the h2o python package is used to interact with it and run h2o algorithms. all pure h2o calls are executed via h2o’s rest api interface. users can easily integrate their regular pyspark workflow with h2o algorithms using pysparkling.

宁夏微乐滑水麻将下载pysparkling programs can be launched as an application or in an interactive shell or notebook environment.

PySparkling and Spark Version

宁夏微乐滑水麻将下载there are multiple pysparkling packages, each is intended to be used with different spark version.

for example, to install pysparkling for spark 2.3, the command would look like:

pip install h2o_pysparkling_2.3

Dependencies

supported python versions are python 2.7 or python 3+.

in order to use pysparkling, it requires the following runtime python dependencies to be available on the system, all of which are available on pypi:

$ pip install requests
$ pip install tabulate
$ pip install future
$ pip install colorama>=0.3.8
$ pip install numpy>=1.9.2

宁夏微乐滑水麻将下载the required packages are installed automatically in case when pysparkling is installed from pypi.

The Sparkling Water Python Module

Prepare the environment

  1. download and unpack sparkling water release from .

  2. configure the location of spark distribution and cluster:

export SPARK_HOME="/path/to/spark/installation"
export MASTER='local[*]'

Run PySparkling interactive shell

  1. ensure you are in the sparkling water project directory and run pysparkling shell:

bin/pysparkling

The pysparkling shell accepts common pyspark宁夏微乐滑水麻将下载 arguments.

For running on YARN and other supported platforms please see Supported Platforms.

  1. initialize h2ocontext

from pysparkling import *
import h2o
hc = H2OContext.getOrCreate(spark)

Run IPython Notebook with PySparkling

PYSPARK_DRIVER_PYTHON="ipython" PYSPARK_DRIVER_PYTHON_OPTS="notebook" bin/pysparkling

for running on windows, the syntax would be:

SET PYSPARK_DRIVER_PYTHON=ipython
SET PYSPARK_DRIVER_PYTHON_OPTS=notebook
bin/pysparkling

Run IPython with PySparkling

PYSPARK_DRIVER_PYTHON="ipython" bin/pysparkling

Use PySparkling in Databricks Cloud

in order to use pysparkling in databricks cloud, pysparkling module has to be added as a library to the current cluster. pysparkling can be added as library in two ways. you can either upload the pysparkling source zip file or add the pysparkling module from pypi.

If you choose to upload PySparkling zip file, don’t forget to add PySparkling Dependencies. The PySparkling zip file is available in py/dist directory of Sparkling Water distribution package.