Distributing Matrix Computations with Spark MLlib Reza Zadeh A - - PowerPoint PPT Presentation

distributing matrix computations with spark mllib
SMART_READER_LITE
LIVE PREVIEW

Distributing Matrix Computations with Spark MLlib Reza Zadeh A - - PowerPoint PPT Presentation

Distributing Matrix Computations with Spark MLlib Reza Zadeh A General Platform Standard libraries included with Spark Spark MLlib Spark SQL GraphX Streaming machine structured graph learning real-time Spark Core Outline Introduction to


slide-1
SLIDE 1

Reza Zadeh

Distributing Matrix Computations with Spark MLlib

slide-2
SLIDE 2

A General Platform

Spark Core Spark Streaming

real-time

Spark SQL

structured

GraphX

graph

MLlib

machine learning

Standard libraries included with Spark

slide-3
SLIDE 3

Outline

Introduction to MLlib Example Invocations Benefits of Iterations: Optimization Singular Value Decomposition All-pairs Similarity Computation MLlib + {Streaming, GraphX, SQL}

slide-4
SLIDE 4

Introduction

slide-5
SLIDE 5

MLlib History

MLlib is a Spark subproject providing machine learning primitives Initial contribution from AMPLab, UC Berkeley Shipped with Spark since Sept 2013

slide-6
SLIDE 6

MLlib: Available algorithms

classification: classification: logistic regression, linear SVM, naïve Bayes, least squares, classification tree regr egression: ession: generalized linear models (GLMs), regression tree collaborative filtering: collaborative filtering: alternating least squares (ALS), non-negative matrix factorization (NMF) clustering: clustering: k-means|| decomposition: decomposition: SVD, PCA

  • ptimization:
  • ptimization: stochastic gradient descent, L-BFGS
slide-7
SLIDE 7

Example Invocations

slide-8
SLIDE 8

Example: K-means

slide-9
SLIDE 9

Example: PCA

slide-10
SLIDE 10

Example: ALS

slide-11
SLIDE 11

Benefits of fast iterations

slide-12
SLIDE 12

Optimization

At least two large classes of optimization problems humans can solve:

  • Convex Programs
  • Spectral Problems (SVD)
slide-13
SLIDE 13

Optimization - LR

data ¡= ¡spark.textFile(...).map(readPoint).cache() ¡ ¡ w ¡= ¡numpy.random.rand(D) ¡ ¡ for ¡i ¡in ¡range(iterations): ¡ ¡ ¡ ¡ ¡gradient ¡= ¡data.map(lambda ¡p: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(1 ¡/ ¡(1 ¡+ ¡exp(-­‑p.y ¡* ¡w.dot(p.x)))) ¡* ¡p.y ¡* ¡p.x ¡ ¡ ¡ ¡ ¡).reduce(lambda ¡a, ¡b: ¡a ¡+ ¡b) ¡ ¡ ¡ ¡ ¡w ¡-­‑= ¡gradient ¡ ¡ print ¡“Final ¡w: ¡%s” ¡% ¡w ¡

slide-14
SLIDE 14

Spark PageRank

Using cache(), keep neighbor lists in RAM Using partitioning, avoid repeated hashing

Neighbors (id, edges) Ranks (id, rank)

join partitionBy join join

slide-15
SLIDE 15

PageRank Results

171 72 23 50 100 150 200 Time per iteration (s) ime per iteration (s) Hadoop Basic Spark Spark + Controlled Partitioning

slide-16
SLIDE 16

Spark PageRank

Generalizes ¡to ¡Matrix ¡Multiplication, ¡opening ¡many ¡algorithms ¡ from ¡Numerical ¡Linear ¡Algebra ¡

slide-17
SLIDE 17

Deep Dive: Singular Value Decomposition

slide-18
SLIDE 18

Singular Value Decomposition

Two cases: Tall and Skinny vs roughly Square computeSVD function takes care of which

  • ne to call, so you don’t have to.
slide-19
SLIDE 19

SVD selection

slide-20
SLIDE 20

Tall and Skinny SVD

slide-21
SLIDE 21

Tall and Skinny SVD

Gets ¡us ¡ ¡ ¡V ¡and ¡the ¡ singular ¡values ¡ Gets ¡us ¡ ¡ ¡U ¡by ¡one ¡ matrix ¡multiplication ¡

slide-22
SLIDE 22

Square SVD via ARPACK

Very mature Fortran77 package for computing eigenvalue decompositions JNI interface available via netlib-java Distributed using Spark

slide-23
SLIDE 23

Square SVD via ARPACK

Only needs to compute matrix vector multiplies to build Krylov subspaces The result of matrix-vector multiply is small The multiplication can be distributed

slide-24
SLIDE 24

Deep Dive: All pairs Similarity

slide-25
SLIDE 25

Deep Dive: All pairs Similarity

Compute via DIMSUM: “Dimension Independent Similarity Computation using MapReduce” Will be in Spark 1.2 as a method in RowMatrix

slide-26
SLIDE 26

All-pairs similarity computation

slide-27
SLIDE 27

Naïve Approach

slide-28
SLIDE 28

Naïve approach: analysis

slide-29
SLIDE 29

DIMSUM Sampling

slide-30
SLIDE 30

DIMSUM Analysis

slide-31
SLIDE 31

Spark implementation

slide-32
SLIDE 32

Ongoing Work in MLlib

stats library (e.g. stratified sampling, ScaRSR) ADMM LDA General Convex Optimization

slide-33
SLIDE 33

MLlib + {Streaming, GraphX, SQL}

slide-34
SLIDE 34

MLlib + Streaming

As of Spark 1.1, you can train linear models in a streaming fashion Model weights are updated via SGD, thus amenable to streaming More work needed for decision trees

slide-35
SLIDE 35

MLlib + SQL

points = context.sql(“select latitude, longitude from tweets”) model = KMeans.train(points, 10)

slide-36
SLIDE 36

MLlib + GraphX

slide-37
SLIDE 37

Future of MLlib

slide-38
SLIDE 38

General Linear Algebra

CoordinateMatrix RowMatrix BlockMatrix Local and distributed versions. Operations in-between.

Goal: ¡version ¡1.2 ¡ Goal: ¡version ¡1.3 ¡

slide-39
SLIDE 39

Research Goal: General Convex Optimization

Distribute ¡CVX ¡by ¡ backing ¡CVXPY ¡with ¡ PySpark ¡ ¡ Easy-­‑to-­‑express ¡ distributable ¡convex ¡ programs ¡ ¡ Need ¡to ¡know ¡less ¡ math ¡to ¡optimize ¡ complicated ¡

  • bjectives ¡
slide-40
SLIDE 40

Spark and ML

Spark has all its roots in research, so we hope to keep incorporating new ideas!