DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Getting Started With Spark Machine Learning on Bluemix

Getting Started With Spark Machine Learning on Bluemix

Niklas Heidloff gives an overview of Spark ML with plenty of links to samples.

Niklas Heidloff user avatar by
Niklas Heidloff
CORE ·
May. 23, 16 · Tutorial
Like (2)
Save
Tweet
Share
4.65K Views

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.

image title

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.

sparkml1

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.

sparkml2

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://169.54.219.20 \
./target/scala-2.10/hellospark_2.10-1.0.jar file://spark-submit_20160305165113.log
Machine learning Bluemix

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • DZone's Article Submission Guidelines
  • What Was the Question Again, ChatGPT?
  • How to Submit a Post to DZone
  • Microservices Discovery With Eureka

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: