Getting Started With Spark Machine Learning on Bluemix
Niklas Heidloff gives an overview of Spark ML with plenty of links to samples.
Join the DZone community and get the full member experience.Join For Free
i’m fascinated by the power of machine learning and i’m trying to learn more about this technology. i’ve started to look into how to use the machine learning library in spark.
the spark documentation of the spark.ml package explains the main concepts like pipelines and transformers pretty well. there are also a number of good videos on youtube about machine learning. i’ve used the spark.ml library as opposed to spark.mllib since it’s the recommended approach and it uses spark dataframes which makes the code easier.
ibm bluemix provides an apache spark service that i’ve used to run samples. the simplest way to get started is to follow the bluemix tutorial . there is a simple sample scala notebook to determine the top drop off locations for new york city taxis.
in addition to the taxi sample and the simple samples in the spark documentation there are more samples on github. make sure you use the samples of the 1.6 branch since that is the spark version currently supported on bluemix. i’ve chosen scala as the programming language since most of the machine learning samples i’ve seen have been written in scala, plus there are good ways to debug this code.
the spark machine learning samples can be run on bluemix in two different ways. either as notebooks or as spark applications . the advantage of notebooks is that you don’t have to set up anything. however it’s more difficult to debug code.
to run the spark samples in notebooks you need to copy and paste only subsets of them. let’s take the machine learning algorithm kmeans as an example. essentially you only need the code between ‘// $example on$’ and ‘// $example off$’. in order to get the sqlcontext i added ‘val sqlcontext = new org.apache.spark.sql.sqlcontext(sc)’ to the notebook. you also need to remove the spaces before the ‘.xxx’ when lines break since notebooks don’t seem to like this.
while notebooks are easy to get started, i switched to a local scala ide to build and run these samples. the advantage is that with a local ide you can debug and test your code better. my colleague david taieb describes in this article how to set up a local scala ide. the instructions are easy to follow. just make sure to use the spark version 1.6.0 in sbt.build (rather than 1.3.1).
here is a screenshot of the same sample running in my ide. the class name of the sample needs to be defined in the program arguments in the run configuration dialog.
in order to run the application on bluemix use the script spark-submit.sh .
./spark-submit.sh \ --vcap ./vcap.json \ --deploy-mode cluster \ --class org.apache.spark.examples.ml.kmeansexample \ --master https://126.96.36.199 \ ./target/scala-2.10/hellospark_2.10-1.0.jar file://spark-submit_20160305165113.log
Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.