Reader small image

You're reading from  Scala Data Analysis Cookbook

Product typeBook
Published inOct 2015
Reading LevelIntermediate
Publisher
ISBN-139781784396749
Edition1st Edition
Languages
Right arrow
Author (1)
Arun Manivannan
Arun Manivannan
author image
Arun Manivannan

Arun Manivannan has been an engineer in various multinational companies, tier-1 financial institutions, and start-ups, primarily focusing on developing distributed applications that manage and mine data. His languages of choice are Scala and Java, but he also meddles around with various others for kicks. He blogs at http://rerun.me. Arun holds a master's degree in software engineering from the National University of Singapore. He also holds degrees in commerce, computer applications, and HR management. His interests and education could probably be a good dataset for clustering.
Read more about Arun Manivannan

Right arrow

Using StreamingLogisticRegression to classify a Twitter stream using Kafka as a training stream


In the previous recipe, we published all the tweets that were stored in ElasticSearch to a Kafka topic. In this recipe, we'll subscribe to the Kafka stream and train a classification model out of it. We will later use this trained model to classify a live Twitter stream.

How to do it...

This is a really small recipe that is composed of 3 steps:

  1. Subscribing to a Kafka stream: There are two ways to subscribe to a Kafka stream and we'll be using the DirectStream method, which is faster. Just like Twitter streaming, Spark has first-class support for subscribing to a Kafka stream. This is achieved by adding the spark-streaming-kafka dependency. Let's add it to our build.sbt file:

    "org.apache.spark" %% "spark-streaming-kafka" % sparkVersion

    The subscription process is more or less the reverse of the publishing process even in terms of the properties that we pass to Kafka:

    val topics = Set("twtopic")
    val kafkaParams...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Scala Data Analysis Cookbook
Published in: Oct 2015Publisher: ISBN-13: 9781784396749

Author (1)

author image
Arun Manivannan

Arun Manivannan has been an engineer in various multinational companies, tier-1 financial institutions, and start-ups, primarily focusing on developing distributed applications that manage and mine data. His languages of choice are Scala and Java, but he also meddles around with various others for kicks. He blogs at http://rerun.me. Arun holds a master's degree in software engineering from the National University of Singapore. He also holds degrees in commerce, computer applications, and HR management. His interests and education could probably be a good dataset for clustering.
Read more about Arun Manivannan