Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Machine Learning with Spark. - Second Edition

You're reading from  Machine Learning with Spark. - Second Edition

Product type Book
Published in Apr 2017
Publisher Packt
ISBN-13 9781785889936
Pages 532 pages
Edition 2nd Edition
Languages
Authors (2):
Rajdeep Dua Rajdeep Dua
Profile icon Rajdeep Dua
Manpreet Singh Ghotra Manpreet Singh Ghotra
Profile icon Manpreet Singh Ghotra
View More author details
Toc

Table of Contents (13) Chapters close

Preface 1. Getting Up and Running with Spark 2. Math for Machine Learning 3. Designing a Machine Learning System 4. Obtaining, Processing, and Preparing Data with Spark 5. Building a Recommendation Engine with Spark 6. Building a Classification Model with Spark 7. Building a Regression Model with Spark 8. Building a Clustering Model with Spark 9. Dimensionality Reduction with Spark 10. Advanced Text Processing with Spark 11. Real-Time Machine Learning with Spark Streaming 12. Pipeline APIs for Spark ML

Word2Vec with Spark ML on the 20 Newsgroups dataset

In this section, we look at how to use the Spark ML DataFrame and newer implementations from Spark 2.0.X to create a Word2Vector model.

We will create a DataFrame from the dataSet:

val spConfig = (new 
SparkConf).setMaster("local").setAppName("SparkApp")
val spark = SparkSession
.builder
.appName("Word2Vec Sample").config(spConfig)
.getOrCreate()
import spark.implicits._
val rawDF = spark.sparkContext
.wholeTextFiles("./data/20news-bydate-train/alt.atheism/*")
val temp = rawDF.map( x => {
(x._2.filter(_ >= ' ').filter(! _.toString.startsWith("(")) )
})
val textDF = temp.map(x => x.split(" ")).map(Tuple1.apply)
.toDF("text")

This will be followed by creating the Word2Vec class and training the model on the DataFrame textDF created above:

val word2Vec = new Word2Vec...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime}