Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Artificial Intelligence for Big Data

You're reading from   Artificial Intelligence for Big Data Complete guide to automating Big Data solutions using Artificial Intelligence techniques

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781788472173
Length 384 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
 Deshpande Deshpande
Author Profile Icon Deshpande
Deshpande
 Kumar Kumar
Author Profile Icon Kumar
Kumar
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
1. Big Data and Artificial Intelligence Systems 2. Ontology for Big Data FREE CHAPTER 3. Learning from Big Data 4. Neural Network for Big Data 5. Deep Big Data Analytics 6. Natural Language Processing 7. Fuzzy Systems 8. Genetic Programming 9. Swarm Intelligence 10. Reinforcement Learning 11. Cyber Security 12. Cognitive Computing 1. Other Books You May Enjoy Index

Implementing sentiment analysis


In the following code snippet, we have implemented sentiment analysis based on the NLP theory we discussed in this chapter. It uses SPARK libraries on Tweeter JSON records to train models for identifying sentiments like happy or unhappy. It looks for keywords like happy in the twitter messages and then flags it with value 1 indicating that this message represents a happy sentiment. Other messages are flagged with value 0 which represents unhappy sentiment. Finally TF-IDF algorithm is applied to train models: 

import org.apache.spark.ml.feature.{HashingTF, RegexTokenizer, StopWordsRemover, IDF}
import org.apache.spark.sql.functions._
import org.apache.spark.ml.classification.LogisticRegression
import org.apache.spark.ml.Pipeline
import org.apache.spark.ml.classification.MultilayerPerceptronClassifier
import org.apache.spark.ml.evaluation.MulticlassClassificationEvaluator
import scala.util.{Success, Try}
import sqlContext.implicits._

val sqlContext = new org...
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 $15.99/month. Cancel anytime
Visually different images