SlideShare a Scribd company logo
1 of 3
Download to read offline
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 05 Issue: 03 | Mar-2018 www.irjet.net p-ISSN: 2395-0072
ยฉ 2018, IRJET | Impact Factor value: 6.171 | ISO 9001:2008 Certified Journal | Page 546
Sentiment Analysis of Election Result based on Twitter Data using R
Poli Ghosh1, K.Vanitha2
1P.G. Student, GITAM institute of science, GITAM University, Visakhapatnam 530045, India
2Assistant Professor, GITAM institute of science, GITAM University, Visakhapatnam 530045, India
---------------------------------------------------------------------***---------------------------------------------------------------------
Abstract โ€“ With the increase in the collection of texts
obtained from various sources, the need to extract useful
information from the texts in short span of time has also
increased. To solve this problem, text mining is used. These
information can further be used to providebetterservicessuch
as setting trends, calculating sentiment analysis, graphical
representation etc. Here, first the tweets of the people before
as well as after the election are obtained from twitter. These
tweets are then converted into text formats. These texts are
then imported into R. They are then cleaned and made unified
using various functions provided by text mining package in
R[2]. Sentiment analysis is then calculated by comparing the
positive and negative terms[1] which gives result. The text is
then represented in the form of wordcloudwherethekeywords
are depicted of the size according to their importance. An
important keyword is represented with greater size as
compared to other keywords. Representation of data in the
form of Wordcloud is used because of quick visualization.
Key Words: Text Mining, R, Text import, Text cleaning,
Sentiment analysis, Election result, Wordcloud.
1. INTRODUCTION
Users obtain texts in unstructured form from various
sources such as financial and businessreports,newsarticles,
books, blog posts, messagesor posts from social networking
and other social media sites in ever increasing amounts.
Therefore, there is a need to extract the information from
these texts. In this paper, we calculate sentiment analysis of
the election data collected from twitter before as well as
after the election using R infrastructure. The results of the
sentiment analysis will help us to understand peopleโ€™s
opinion before and after the election. Greater the positive
value of sentiment analysis, greater the positive attitude of
the people. Similarly a negative value of the sentiment
analysis shows a negative attitude and a zero value shows
neutral attitude of the people. Firstly, the tweets of the
people before and after the election are collected. These
tweets are then converted into two text files, one containing
the tweets before the election and the other after the
election. Each of these text files are then imported into R.
These files are then cleaned with the help of text mining
package in R. Sentiment analysis is then calculated by
comparing the positive and negative terms[1]. Lastly, each
text document is represented by wordcloud. Wordcloud is
the graphical representation of the text which givesthe user
a quick visualization of the important termsused in the text.
Wordcloud is implemented by using the wordcloud package
available in R.
2. IMPORT TEXT IN R
The text files containing few tweets of before as well as after
the election are savedin the currentworkingdirectoryofRin
.txt format. These texts are imported into R by using R
tools[3].
> getwd()
This functionis used toobtain the current workingdirectory.
>readLines(โ€œbeforeTrump.txtโ€)
>readLines(โ€œafterTrump.txtโ€)
This function is used to read line by line of the text files
โ€œbeforeTrump.txtโ€, โ€œafterTrump.txtโ€ of before and after
election respectively.
2. CLEAN TEXT IN R
The above imported text files are cleaned[2] by applying
various functions of R[3].
>text1 <- paste(readLines (โ€œbeforeTrump.txtโ€), collapse=โ€ โ€œ)
>text4 <- paste(readLines (โ€œafterTrump.txtโ€), collapse=โ€ โ€œ)
Thepaste() function is usedtomake the entire contentof the
text file into a single line and then the result is assigned to
variables text1 and text4.
>text2 <- gsub(pattern=โ€Wโ€, replace=โ€ โ€œ, text1)
>text5 <- gsub(pattern=โ€Wโ€, replace=โ€ โ€œ, text4)
The above script replaces all the punctuations with spaces
from text1 and text4 and assigns theresults in text2 and text5
respectively.
>text3 <- gsub(pattern=โ€dโ€, replace=โ€ โ€œ, text2)
>text6 <- gsub(pattern=โ€dโ€, replace=โ€ โ€œ, text5)
The above scriptreplacesallthedigitswith spacesfromtext2
and text5 and assigns the results in text3 and text6
respectively.
>text3 <- tolower(text3)
>text6 <- tolower(text6)
The above script lowercases all the words in text3 and text6
and assigns the results in text3 and text6 respectively.
>install.packages(โ€œtmโ€)
The above script install the text mining packagenamed โ€œtmโ€.
>library(tm)
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 05 Issue: 03 | Mar-2018 www.irjet.net p-ISSN: 2395-0072
ยฉ 2018, IRJET | Impact Factor value: 6.171 | ISO 9001:2008 Certified Journal | Page 547
The above script makes available the โ€œtmโ€ library into R.
>text3 <- removeWords(text3, stopwords())
>text6 <- removeWords(text6, stopwords())
The removeWords() and stopwords() functions are available
in โ€œtmโ€ library[5]. Using these functions the stopwords are
removed from the texts, i.e., text3 and text6. The stopwords()
function includes the list of words which are not useful for
analysis.
>text3 <- gsub(pattern= b[A-z]b{1} , replace=โ€ โ€œ, text3)
>text6 <- gsub(pattern= b[A-z]b{1} , replace=โ€ โ€œ, text6)
The above script replaces all the single character of length
one with spaces from text3 and text6 and assigns the results
in text3 and text6 respectively.
>text3 <- stripWhitespace(text3)
>text6 <- stripWhitespace(text6)
The above script removes all the extra white spaces from
text3 and text6 and assigns the results in text3 and text6
respectively.
3. SENTIMENT ANALYSIS IN R
Sentiment analysis is calculated by comparing positive and
negative words[7][8]. The result of sentiment analysis of
each file shows the opinion of the people[6].
>install.packages(โ€œstringrโ€)
The above script installs the package named โ€œstringrโ€ which
increases our capability of working with strings.
>library (stringr)
The above script makes available the โ€œstringrโ€ library into R.
>tbag1 <- str_split(text3, pattern=s+)
>tbag2 <- str_split(text6, pattern=s+)
The str_split() function is available in โ€œstringrโ€ library. This
function splits the string into individual words and assigns
the results into tbag1 and tbag2.
>tbag1 <- unlist(tbag1)
>tbag2 <- unlist(tbag2)
The above scriptunlists the content ofthe tbag1andtbag2as
a result of which it no more belongs to the list class. Now the
variables tbag1 and tbag2 belongs to the character class.
>poswords <- scan(โ€˜positiveWords.txtโ€™, what=โ€™characterโ€™,
comment.char=โ€;โ€)
>negwords <- scan(โ€˜negativeWords.txtโ€™, what=โ€™characterโ€™,
comment.char=โ€;โ€)
The above script assigns all the characters from the
โ€˜positiveWords.txtโ€™ and โ€˜negativeWords.txtโ€™ files to the
variables poswords and negwords respectively[1].
>sum(! is.na (match(tbag1,poswords)))
[1] 130
>sum(! is.na (match(tbag1,negwords)))
[2] 34
>score1 <- sum(! is.na (match(tbag1,poswords)))- sum(! is.na
(match(tbag1,negwords)))
>score1
[1] 96
>sum(! is.na (match(tbag2,poswords)))
[1] 90
>sum(! is.na (match(tbag2,negwords)))
[1] 63
>score2 <- sum(! is.na (match(tbag2,poswords)))- sum(! is.na
(match(tbag2,negwords)))
>score2
[1] 27
In the above scripts, first the sum of the positive and the
negative matched terms are displayed. The scores are
calculated by subtracting the results of the sum of the
positive and thenegative matchedterms. The value of score1
is the valueof the sentiment analysis of text1 andthe valueof
score2 is the value of the sentiment analysis of text1.
4. WORDCLOUD IN R
>install.packages(โ€œwordcloudโ€)
The above script installs the package named โ€œwordcloudโ€
using which a wordcloud can be represented[3].
>library (wordcloud)
The above script makes available the โ€œwordcloudโ€ library
into R.
>Wordcloud(tbag1, min.freq=1, max.words=200,
random.order=FALSE, rot.per=0.35,
colors=brewer.pal(8,โ€Dark2โ€))
Fig -1: Wordcloud of text before election
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 05 Issue: 03 | Mar-2018 www.irjet.net p-ISSN: 2395-0072
ยฉ 2018, IRJET | Impact Factor value: 6.171 | ISO 9001:2008 Certified Journal | Page 548
>Wordcloud(tbag2, min.freq=1, max.words=200,
random.order=FALSE, rot.per=0.35,
colors=brewer.pal(8,โ€Dark2โ€))
Fig -1: Wordcloud of text after election
5. CONCLUSIONS
In this paper, we calculate sentiment analysisof theelection
data collected from twitter before and after the election
using R infrastructure and also use wordcloud to represent
information. Here the calculated sentiment analysis before
the result is 96 whereas the calculated sentiment analysis
after the result is 27. So, from the above results we can
conclude that the people after the election are not satisfied.
The wordcloud from the text containing tweets of before
election shows trump, real Donald trump, will, make
America great again, people, cnn etc., are the most frequent
words used among the users whereas the wordcloud from
the text containing tweets of after election showswill, thank
you tour, kennedy, today, president, election, jobs, state etc.,
are the most frequent words used.
REFERENCES
[1] Bing Liu, Minqing Hu and Junsheng Cheng. "Opinion
Observer: Analyzing and Comparing Opinions on the
Web." Proceedings of the 14th International World
Wide Web conference (WWW-2005), May 10-14, 2005,
Chiba, Japan.
[2] Adeva JJG, Calvo R (2006). Mining Text with Pimiento."
IEEE Internet Computing,10(4),27{35.ISSN1089-7801.
doi:10.1109/MIC.2006.85.
[3] Feinerer, K. Hornik, and D. Meyer. Text mining
infrastructure in R. Journal of StatisticalSoftware,25(5):
1{54, March 2008. ISSN 1548-7660. URL
http://www.jstatsoft.org/v25/i05.
[4] Feinerer. An introduction to text mining in R. R News,
8(2):19{22, Oct. 2008. URL http://CRAN.R-
project.org/doc/Rnews/.
[5] Arnold, T. (2017a). cleannlp: A tidy data model for
natural language processing [Computer software
manual] (R package version 1.9.0). Retrieved from
https://CRAN.R-project.org/package=cleanNLP
[6] B. Pang and L. Lee. 2004. A sentimental education:
Sentiment analysis using subjectivity analysis using
subjectivity summarization based on minimum cuts.
ACL.
[7] Balahur, A., Steinberger, R., Kabadjov, M., Zavarella, V.,
vander Goot, E., Halkia, M., Pouliquen, B., andBelyaeva,J.
(2010):Sentiment Analysis in the News. In: Proceedings
of the 7th International Conference on Language
Resources and Evaluation (LREC2010), pp. 2216-2220.
[8] T.Wilson, J.Wiebe, and P. Hoffman. 2005. Recognizing
contextual polarity in phrase level sentiment analysis.
ACL.
BIOGRAPHY
Poli Ghosh pursuing Master of
Computer Applications, GIS, GITAM
University, Visakhapatnam. Her area
of interest is sentiment analysis and
text mining.
K.Vanitha is currently working as
Assistant Professor in the
Department of ComputerScience,GIS,
GITAM University. Her main areas of
research includes Data Mining.

More Related Content

What's hot

Query expansion_Team42_IRE2k14
Query expansion_Team42_IRE2k14Query expansion_Team42_IRE2k14
Query expansion_Team42_IRE2k14
sudhir11292rt
ย 
Query expansion_group42_ire
Query expansion_group42_ireQuery expansion_group42_ire
Query expansion_group42_ire
KovidaN
ย 

What's hot (19)

FINDING OUT NOISY PATTERNS FOR RELATION EXTRACTION OF BANGLA SENTENCES
FINDING OUT NOISY PATTERNS FOR RELATION EXTRACTION OF BANGLA SENTENCESFINDING OUT NOISY PATTERNS FOR RELATION EXTRACTION OF BANGLA SENTENCES
FINDING OUT NOISY PATTERNS FOR RELATION EXTRACTION OF BANGLA SENTENCES
ย 
Document clustering and classification
Document clustering and classification Document clustering and classification
Document clustering and classification
ย 
Performance Analysis of Hashing Mathods on the Employment of App
Performance Analysis of Hashing Mathods on the Employment of App Performance Analysis of Hashing Mathods on the Employment of App
Performance Analysis of Hashing Mathods on the Employment of App
ย 
Z04506138145
Z04506138145Z04506138145
Z04506138145
ย 
SOURCE CODE RETRIEVAL USING SEQUENCE BASED SIMILARITY
SOURCE CODE RETRIEVAL USING SEQUENCE BASED SIMILARITYSOURCE CODE RETRIEVAL USING SEQUENCE BASED SIMILARITY
SOURCE CODE RETRIEVAL USING SEQUENCE BASED SIMILARITY
ย 
Query expansion_Team42_IRE2k14
Query expansion_Team42_IRE2k14Query expansion_Team42_IRE2k14
Query expansion_Team42_IRE2k14
ย 
VARIATIONS IN OUTCOME FOR THE SAME MAP REDUCE TRANSITIVE CLOSURE ALGORITHM IM...
VARIATIONS IN OUTCOME FOR THE SAME MAP REDUCE TRANSITIVE CLOSURE ALGORITHM IM...VARIATIONS IN OUTCOME FOR THE SAME MAP REDUCE TRANSITIVE CLOSURE ALGORITHM IM...
VARIATIONS IN OUTCOME FOR THE SAME MAP REDUCE TRANSITIVE CLOSURE ALGORITHM IM...
ย 
Bi4101343346
Bi4101343346Bi4101343346
Bi4101343346
ย 
Query expansion_group42_ire
Query expansion_group42_ireQuery expansion_group42_ire
Query expansion_group42_ire
ย 
Improving Spam Mail Filtering Using Classification Algorithms With Partition ...
Improving Spam Mail Filtering Using Classification Algorithms With Partition ...Improving Spam Mail Filtering Using Classification Algorithms With Partition ...
Improving Spam Mail Filtering Using Classification Algorithms With Partition ...
ย 
Ginix Generalized Inverted Index for Keyword Search
Ginix Generalized Inverted Index for Keyword SearchGinix Generalized Inverted Index for Keyword Search
Ginix Generalized Inverted Index for Keyword Search
ย 
International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)International Journal of Engineering and Science Invention (IJESI)
International Journal of Engineering and Science Invention (IJESI)
ย 
Berlin Hadoop Get Together Apache Drill
Berlin Hadoop Get Together Apache Drill Berlin Hadoop Get Together Apache Drill
Berlin Hadoop Get Together Apache Drill
ย 
An Examination of the Bloom Filter and its Application in Preventing Weak Pas...
An Examination of the Bloom Filter and its Application in Preventing Weak Pas...An Examination of the Bloom Filter and its Application in Preventing Weak Pas...
An Examination of the Bloom Filter and its Application in Preventing Weak Pas...
ย 
A Review on Text Mining in Data Mining
A Review on Text Mining in Data MiningA Review on Text Mining in Data Mining
A Review on Text Mining in Data Mining
ย 
Implementing a data science project (R Version) Part1
Implementing a data science project (R Version) Part1Implementing a data science project (R Version) Part1
Implementing a data science project (R Version) Part1
ย 
Text analytics in Python and R with examples from Tobacco Control
Text analytics in Python and R with examples from Tobacco ControlText analytics in Python and R with examples from Tobacco Control
Text analytics in Python and R with examples from Tobacco Control
ย 
Graphlab Ted Dunning Clustering
Graphlab Ted Dunning  ClusteringGraphlab Ted Dunning  Clustering
Graphlab Ted Dunning Clustering
ย 
Hybrid approach for generating non overlapped substring using genetic algorithm
Hybrid approach for generating non overlapped substring using genetic algorithmHybrid approach for generating non overlapped substring using genetic algorithm
Hybrid approach for generating non overlapped substring using genetic algorithm
ย 

Similar to IRJET- Sentiment Analysis of Election Result based on Twitter Data using R

Sales_Prediction_Technique using R Programming
Sales_Prediction_Technique using R ProgrammingSales_Prediction_Technique using R Programming
Sales_Prediction_Technique using R Programming
Nagarjun Kotyada
ย 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
Eman magdy
ย 

Similar to IRJET- Sentiment Analysis of Election Result based on Twitter Data using R (20)

Sales_Prediction_Technique using R Programming
Sales_Prediction_Technique using R ProgrammingSales_Prediction_Technique using R Programming
Sales_Prediction_Technique using R Programming
ย 
IRJET- Sentimental Analysis for Online Reviews using Machine Learning Algorithms
IRJET- Sentimental Analysis for Online Reviews using Machine Learning AlgorithmsIRJET- Sentimental Analysis for Online Reviews using Machine Learning Algorithms
IRJET- Sentimental Analysis for Online Reviews using Machine Learning Algorithms
ย 
EXECUTION OF ASSOCIATION RULE MINING WITH DATA GRIDS IN WEKA 3.8
EXECUTION OF ASSOCIATION RULE MINING WITH DATA GRIDS IN WEKA 3.8EXECUTION OF ASSOCIATION RULE MINING WITH DATA GRIDS IN WEKA 3.8
EXECUTION OF ASSOCIATION RULE MINING WITH DATA GRIDS IN WEKA 3.8
ย 
Automatic Text Classification Of News Blog using Machine Learning
Automatic Text Classification Of News Blog using Machine LearningAutomatic Text Classification Of News Blog using Machine Learning
Automatic Text Classification Of News Blog using Machine Learning
ย 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
ย 
Implementation of query optimization for reducing run time
Implementation of query optimization for reducing run timeImplementation of query optimization for reducing run time
Implementation of query optimization for reducing run time
ย 
Automatic document clustering
Automatic document clusteringAutomatic document clustering
Automatic document clustering
ย 
Automated Essay Grading using Features Selection
Automated Essay Grading using Features SelectionAutomated Essay Grading using Features Selection
Automated Essay Grading using Features Selection
ย 
A Program for Multiple Sequence Alignment by Star Alignment
A Program for Multiple Sequence Alignment by Star AlignmentA Program for Multiple Sequence Alignment by Star Alignment
A Program for Multiple Sequence Alignment by Star Alignment
ย 
Comparison of Text Classifiers on News Articles
Comparison of Text Classifiers on News ArticlesComparison of Text Classifiers on News Articles
Comparison of Text Classifiers on News Articles
ย 
Optimization of workload prediction based on map reduce frame work in a cloud...
Optimization of workload prediction based on map reduce frame work in a cloud...Optimization of workload prediction based on map reduce frame work in a cloud...
Optimization of workload prediction based on map reduce frame work in a cloud...
ย 
Optimization of workload prediction based on map reduce frame work in a cloud...
Optimization of workload prediction based on map reduce frame work in a cloud...Optimization of workload prediction based on map reduce frame work in a cloud...
Optimization of workload prediction based on map reduce frame work in a cloud...
ย 
A Novel Design For Generating Dynamic Length Message Digest To Ensure Integri...
A Novel Design For Generating Dynamic Length Message Digest To Ensure Integri...A Novel Design For Generating Dynamic Length Message Digest To Ensure Integri...
A Novel Design For Generating Dynamic Length Message Digest To Ensure Integri...
ย 
IRJET- Automatic Database Schema Generator
IRJET- Automatic Database Schema GeneratorIRJET- Automatic Database Schema Generator
IRJET- Automatic Database Schema Generator
ย 
Overview of Movie Recommendation System using Machine learning by R programmi...
Overview of Movie Recommendation System using Machine learning by R programmi...Overview of Movie Recommendation System using Machine learning by R programmi...
Overview of Movie Recommendation System using Machine learning by R programmi...
ย 
Data mining model for the data retrieval from central server configuration
Data mining model for the data retrieval from central server configurationData mining model for the data retrieval from central server configuration
Data mining model for the data retrieval from central server configuration
ย 
A Robust Keywords Based Document Retrieval by Utilizing Advanced Encryption S...
A Robust Keywords Based Document Retrieval by Utilizing Advanced Encryption S...A Robust Keywords Based Document Retrieval by Utilizing Advanced Encryption S...
A Robust Keywords Based Document Retrieval by Utilizing Advanced Encryption S...
ย 
IRJET- Analysis of Music Recommendation System using Machine Learning Alg...
IRJET-  	  Analysis of Music Recommendation System using Machine Learning Alg...IRJET-  	  Analysis of Music Recommendation System using Machine Learning Alg...
IRJET- Analysis of Music Recommendation System using Machine Learning Alg...
ย 
ITB Term Paper - 10BM60066
ITB Term Paper - 10BM60066ITB Term Paper - 10BM60066
ITB Term Paper - 10BM60066
ย 
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
ย 

More from IRJET Journal

More from IRJET Journal (20)

TUNNELING IN HIMALAYAS WITH NATM METHOD: A SPECIAL REFERENCES TO SUNGAL TUNNE...
TUNNELING IN HIMALAYAS WITH NATM METHOD: A SPECIAL REFERENCES TO SUNGAL TUNNE...TUNNELING IN HIMALAYAS WITH NATM METHOD: A SPECIAL REFERENCES TO SUNGAL TUNNE...
TUNNELING IN HIMALAYAS WITH NATM METHOD: A SPECIAL REFERENCES TO SUNGAL TUNNE...
ย 
STUDY THE EFFECT OF RESPONSE REDUCTION FACTOR ON RC FRAMED STRUCTURE
STUDY THE EFFECT OF RESPONSE REDUCTION FACTOR ON RC FRAMED STRUCTURESTUDY THE EFFECT OF RESPONSE REDUCTION FACTOR ON RC FRAMED STRUCTURE
STUDY THE EFFECT OF RESPONSE REDUCTION FACTOR ON RC FRAMED STRUCTURE
ย 
A COMPARATIVE ANALYSIS OF RCC ELEMENT OF SLAB WITH STARK STEEL (HYSD STEEL) A...
A COMPARATIVE ANALYSIS OF RCC ELEMENT OF SLAB WITH STARK STEEL (HYSD STEEL) A...A COMPARATIVE ANALYSIS OF RCC ELEMENT OF SLAB WITH STARK STEEL (HYSD STEEL) A...
A COMPARATIVE ANALYSIS OF RCC ELEMENT OF SLAB WITH STARK STEEL (HYSD STEEL) A...
ย 
Effect of Camber and Angles of Attack on Airfoil Characteristics
Effect of Camber and Angles of Attack on Airfoil CharacteristicsEffect of Camber and Angles of Attack on Airfoil Characteristics
Effect of Camber and Angles of Attack on Airfoil Characteristics
ย 
A Review on the Progress and Challenges of Aluminum-Based Metal Matrix Compos...
A Review on the Progress and Challenges of Aluminum-Based Metal Matrix Compos...A Review on the Progress and Challenges of Aluminum-Based Metal Matrix Compos...
A Review on the Progress and Challenges of Aluminum-Based Metal Matrix Compos...
ย 
Dynamic Urban Transit Optimization: A Graph Neural Network Approach for Real-...
Dynamic Urban Transit Optimization: A Graph Neural Network Approach for Real-...Dynamic Urban Transit Optimization: A Graph Neural Network Approach for Real-...
Dynamic Urban Transit Optimization: A Graph Neural Network Approach for Real-...
ย 
Structural Analysis and Design of Multi-Storey Symmetric and Asymmetric Shape...
Structural Analysis and Design of Multi-Storey Symmetric and Asymmetric Shape...Structural Analysis and Design of Multi-Storey Symmetric and Asymmetric Shape...
Structural Analysis and Design of Multi-Storey Symmetric and Asymmetric Shape...
ย 
A Review of โ€œSeismic Response of RC Structures Having Plan and Vertical Irreg...
A Review of โ€œSeismic Response of RC Structures Having Plan and Vertical Irreg...A Review of โ€œSeismic Response of RC Structures Having Plan and Vertical Irreg...
A Review of โ€œSeismic Response of RC Structures Having Plan and Vertical Irreg...
ย 
A REVIEW ON MACHINE LEARNING IN ADAS
A REVIEW ON MACHINE LEARNING IN ADASA REVIEW ON MACHINE LEARNING IN ADAS
A REVIEW ON MACHINE LEARNING IN ADAS
ย 
Long Term Trend Analysis of Precipitation and Temperature for Asosa district,...
Long Term Trend Analysis of Precipitation and Temperature for Asosa district,...Long Term Trend Analysis of Precipitation and Temperature for Asosa district,...
Long Term Trend Analysis of Precipitation and Temperature for Asosa district,...
ย 
P.E.B. Framed Structure Design and Analysis Using STAAD Pro
P.E.B. Framed Structure Design and Analysis Using STAAD ProP.E.B. Framed Structure Design and Analysis Using STAAD Pro
P.E.B. Framed Structure Design and Analysis Using STAAD Pro
ย 
A Review on Innovative Fiber Integration for Enhanced Reinforcement of Concre...
A Review on Innovative Fiber Integration for Enhanced Reinforcement of Concre...A Review on Innovative Fiber Integration for Enhanced Reinforcement of Concre...
A Review on Innovative Fiber Integration for Enhanced Reinforcement of Concre...
ย 
Survey Paper on Cloud-Based Secured Healthcare System
Survey Paper on Cloud-Based Secured Healthcare SystemSurvey Paper on Cloud-Based Secured Healthcare System
Survey Paper on Cloud-Based Secured Healthcare System
ย 
Review on studies and research on widening of existing concrete bridges
Review on studies and research on widening of existing concrete bridgesReview on studies and research on widening of existing concrete bridges
Review on studies and research on widening of existing concrete bridges
ย 
React based fullstack edtech web application
React based fullstack edtech web applicationReact based fullstack edtech web application
React based fullstack edtech web application
ย 
A Comprehensive Review of Integrating IoT and Blockchain Technologies in the ...
A Comprehensive Review of Integrating IoT and Blockchain Technologies in the ...A Comprehensive Review of Integrating IoT and Blockchain Technologies in the ...
A Comprehensive Review of Integrating IoT and Blockchain Technologies in the ...
ย 
A REVIEW ON THE PERFORMANCE OF COCONUT FIBRE REINFORCED CONCRETE.
A REVIEW ON THE PERFORMANCE OF COCONUT FIBRE REINFORCED CONCRETE.A REVIEW ON THE PERFORMANCE OF COCONUT FIBRE REINFORCED CONCRETE.
A REVIEW ON THE PERFORMANCE OF COCONUT FIBRE REINFORCED CONCRETE.
ย 
Optimizing Business Management Process Workflows: The Dynamic Influence of Mi...
Optimizing Business Management Process Workflows: The Dynamic Influence of Mi...Optimizing Business Management Process Workflows: The Dynamic Influence of Mi...
Optimizing Business Management Process Workflows: The Dynamic Influence of Mi...
ย 
Multistoried and Multi Bay Steel Building Frame by using Seismic Design
Multistoried and Multi Bay Steel Building Frame by using Seismic DesignMultistoried and Multi Bay Steel Building Frame by using Seismic Design
Multistoried and Multi Bay Steel Building Frame by using Seismic Design
ย 
Cost Optimization of Construction Using Plastic Waste as a Sustainable Constr...
Cost Optimization of Construction Using Plastic Waste as a Sustainable Constr...Cost Optimization of Construction Using Plastic Waste as a Sustainable Constr...
Cost Optimization of Construction Using Plastic Waste as a Sustainable Constr...
ย 

Recently uploaded

VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
SUHANI PANDEY
ย 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
ย 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
ย 

Recently uploaded (20)

DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
ย 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
ย 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
ย 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ย 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ย 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
ย 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
ย 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
ย 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
ย 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
ย 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
ย 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
ย 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
ย 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
ย 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
ย 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
ย 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
ย 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
ย 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
ย 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
ย 

IRJET- Sentiment Analysis of Election Result based on Twitter Data using R

  • 1. International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 05 Issue: 03 | Mar-2018 www.irjet.net p-ISSN: 2395-0072 ยฉ 2018, IRJET | Impact Factor value: 6.171 | ISO 9001:2008 Certified Journal | Page 546 Sentiment Analysis of Election Result based on Twitter Data using R Poli Ghosh1, K.Vanitha2 1P.G. Student, GITAM institute of science, GITAM University, Visakhapatnam 530045, India 2Assistant Professor, GITAM institute of science, GITAM University, Visakhapatnam 530045, India ---------------------------------------------------------------------***--------------------------------------------------------------------- Abstract โ€“ With the increase in the collection of texts obtained from various sources, the need to extract useful information from the texts in short span of time has also increased. To solve this problem, text mining is used. These information can further be used to providebetterservicessuch as setting trends, calculating sentiment analysis, graphical representation etc. Here, first the tweets of the people before as well as after the election are obtained from twitter. These tweets are then converted into text formats. These texts are then imported into R. They are then cleaned and made unified using various functions provided by text mining package in R[2]. Sentiment analysis is then calculated by comparing the positive and negative terms[1] which gives result. The text is then represented in the form of wordcloudwherethekeywords are depicted of the size according to their importance. An important keyword is represented with greater size as compared to other keywords. Representation of data in the form of Wordcloud is used because of quick visualization. Key Words: Text Mining, R, Text import, Text cleaning, Sentiment analysis, Election result, Wordcloud. 1. INTRODUCTION Users obtain texts in unstructured form from various sources such as financial and businessreports,newsarticles, books, blog posts, messagesor posts from social networking and other social media sites in ever increasing amounts. Therefore, there is a need to extract the information from these texts. In this paper, we calculate sentiment analysis of the election data collected from twitter before as well as after the election using R infrastructure. The results of the sentiment analysis will help us to understand peopleโ€™s opinion before and after the election. Greater the positive value of sentiment analysis, greater the positive attitude of the people. Similarly a negative value of the sentiment analysis shows a negative attitude and a zero value shows neutral attitude of the people. Firstly, the tweets of the people before and after the election are collected. These tweets are then converted into two text files, one containing the tweets before the election and the other after the election. Each of these text files are then imported into R. These files are then cleaned with the help of text mining package in R. Sentiment analysis is then calculated by comparing the positive and negative terms[1]. Lastly, each text document is represented by wordcloud. Wordcloud is the graphical representation of the text which givesthe user a quick visualization of the important termsused in the text. Wordcloud is implemented by using the wordcloud package available in R. 2. IMPORT TEXT IN R The text files containing few tweets of before as well as after the election are savedin the currentworkingdirectoryofRin .txt format. These texts are imported into R by using R tools[3]. > getwd() This functionis used toobtain the current workingdirectory. >readLines(โ€œbeforeTrump.txtโ€) >readLines(โ€œafterTrump.txtโ€) This function is used to read line by line of the text files โ€œbeforeTrump.txtโ€, โ€œafterTrump.txtโ€ of before and after election respectively. 2. CLEAN TEXT IN R The above imported text files are cleaned[2] by applying various functions of R[3]. >text1 <- paste(readLines (โ€œbeforeTrump.txtโ€), collapse=โ€ โ€œ) >text4 <- paste(readLines (โ€œafterTrump.txtโ€), collapse=โ€ โ€œ) Thepaste() function is usedtomake the entire contentof the text file into a single line and then the result is assigned to variables text1 and text4. >text2 <- gsub(pattern=โ€Wโ€, replace=โ€ โ€œ, text1) >text5 <- gsub(pattern=โ€Wโ€, replace=โ€ โ€œ, text4) The above script replaces all the punctuations with spaces from text1 and text4 and assigns theresults in text2 and text5 respectively. >text3 <- gsub(pattern=โ€dโ€, replace=โ€ โ€œ, text2) >text6 <- gsub(pattern=โ€dโ€, replace=โ€ โ€œ, text5) The above scriptreplacesallthedigitswith spacesfromtext2 and text5 and assigns the results in text3 and text6 respectively. >text3 <- tolower(text3) >text6 <- tolower(text6) The above script lowercases all the words in text3 and text6 and assigns the results in text3 and text6 respectively. >install.packages(โ€œtmโ€) The above script install the text mining packagenamed โ€œtmโ€. >library(tm)
  • 2. International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 05 Issue: 03 | Mar-2018 www.irjet.net p-ISSN: 2395-0072 ยฉ 2018, IRJET | Impact Factor value: 6.171 | ISO 9001:2008 Certified Journal | Page 547 The above script makes available the โ€œtmโ€ library into R. >text3 <- removeWords(text3, stopwords()) >text6 <- removeWords(text6, stopwords()) The removeWords() and stopwords() functions are available in โ€œtmโ€ library[5]. Using these functions the stopwords are removed from the texts, i.e., text3 and text6. The stopwords() function includes the list of words which are not useful for analysis. >text3 <- gsub(pattern= b[A-z]b{1} , replace=โ€ โ€œ, text3) >text6 <- gsub(pattern= b[A-z]b{1} , replace=โ€ โ€œ, text6) The above script replaces all the single character of length one with spaces from text3 and text6 and assigns the results in text3 and text6 respectively. >text3 <- stripWhitespace(text3) >text6 <- stripWhitespace(text6) The above script removes all the extra white spaces from text3 and text6 and assigns the results in text3 and text6 respectively. 3. SENTIMENT ANALYSIS IN R Sentiment analysis is calculated by comparing positive and negative words[7][8]. The result of sentiment analysis of each file shows the opinion of the people[6]. >install.packages(โ€œstringrโ€) The above script installs the package named โ€œstringrโ€ which increases our capability of working with strings. >library (stringr) The above script makes available the โ€œstringrโ€ library into R. >tbag1 <- str_split(text3, pattern=s+) >tbag2 <- str_split(text6, pattern=s+) The str_split() function is available in โ€œstringrโ€ library. This function splits the string into individual words and assigns the results into tbag1 and tbag2. >tbag1 <- unlist(tbag1) >tbag2 <- unlist(tbag2) The above scriptunlists the content ofthe tbag1andtbag2as a result of which it no more belongs to the list class. Now the variables tbag1 and tbag2 belongs to the character class. >poswords <- scan(โ€˜positiveWords.txtโ€™, what=โ€™characterโ€™, comment.char=โ€;โ€) >negwords <- scan(โ€˜negativeWords.txtโ€™, what=โ€™characterโ€™, comment.char=โ€;โ€) The above script assigns all the characters from the โ€˜positiveWords.txtโ€™ and โ€˜negativeWords.txtโ€™ files to the variables poswords and negwords respectively[1]. >sum(! is.na (match(tbag1,poswords))) [1] 130 >sum(! is.na (match(tbag1,negwords))) [2] 34 >score1 <- sum(! is.na (match(tbag1,poswords)))- sum(! is.na (match(tbag1,negwords))) >score1 [1] 96 >sum(! is.na (match(tbag2,poswords))) [1] 90 >sum(! is.na (match(tbag2,negwords))) [1] 63 >score2 <- sum(! is.na (match(tbag2,poswords)))- sum(! is.na (match(tbag2,negwords))) >score2 [1] 27 In the above scripts, first the sum of the positive and the negative matched terms are displayed. The scores are calculated by subtracting the results of the sum of the positive and thenegative matchedterms. The value of score1 is the valueof the sentiment analysis of text1 andthe valueof score2 is the value of the sentiment analysis of text1. 4. WORDCLOUD IN R >install.packages(โ€œwordcloudโ€) The above script installs the package named โ€œwordcloudโ€ using which a wordcloud can be represented[3]. >library (wordcloud) The above script makes available the โ€œwordcloudโ€ library into R. >Wordcloud(tbag1, min.freq=1, max.words=200, random.order=FALSE, rot.per=0.35, colors=brewer.pal(8,โ€Dark2โ€)) Fig -1: Wordcloud of text before election
  • 3. International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 05 Issue: 03 | Mar-2018 www.irjet.net p-ISSN: 2395-0072 ยฉ 2018, IRJET | Impact Factor value: 6.171 | ISO 9001:2008 Certified Journal | Page 548 >Wordcloud(tbag2, min.freq=1, max.words=200, random.order=FALSE, rot.per=0.35, colors=brewer.pal(8,โ€Dark2โ€)) Fig -1: Wordcloud of text after election 5. CONCLUSIONS In this paper, we calculate sentiment analysisof theelection data collected from twitter before and after the election using R infrastructure and also use wordcloud to represent information. Here the calculated sentiment analysis before the result is 96 whereas the calculated sentiment analysis after the result is 27. So, from the above results we can conclude that the people after the election are not satisfied. The wordcloud from the text containing tweets of before election shows trump, real Donald trump, will, make America great again, people, cnn etc., are the most frequent words used among the users whereas the wordcloud from the text containing tweets of after election showswill, thank you tour, kennedy, today, president, election, jobs, state etc., are the most frequent words used. REFERENCES [1] Bing Liu, Minqing Hu and Junsheng Cheng. "Opinion Observer: Analyzing and Comparing Opinions on the Web." Proceedings of the 14th International World Wide Web conference (WWW-2005), May 10-14, 2005, Chiba, Japan. [2] Adeva JJG, Calvo R (2006). Mining Text with Pimiento." IEEE Internet Computing,10(4),27{35.ISSN1089-7801. doi:10.1109/MIC.2006.85. [3] Feinerer, K. Hornik, and D. Meyer. Text mining infrastructure in R. Journal of StatisticalSoftware,25(5): 1{54, March 2008. ISSN 1548-7660. URL http://www.jstatsoft.org/v25/i05. [4] Feinerer. An introduction to text mining in R. R News, 8(2):19{22, Oct. 2008. URL http://CRAN.R- project.org/doc/Rnews/. [5] Arnold, T. (2017a). cleannlp: A tidy data model for natural language processing [Computer software manual] (R package version 1.9.0). Retrieved from https://CRAN.R-project.org/package=cleanNLP [6] B. Pang and L. Lee. 2004. A sentimental education: Sentiment analysis using subjectivity analysis using subjectivity summarization based on minimum cuts. ACL. [7] Balahur, A., Steinberger, R., Kabadjov, M., Zavarella, V., vander Goot, E., Halkia, M., Pouliquen, B., andBelyaeva,J. (2010):Sentiment Analysis in the News. In: Proceedings of the 7th International Conference on Language Resources and Evaluation (LREC2010), pp. 2216-2220. [8] T.Wilson, J.Wiebe, and P. Hoffman. 2005. Recognizing contextual polarity in phrase level sentiment analysis. ACL. BIOGRAPHY Poli Ghosh pursuing Master of Computer Applications, GIS, GITAM University, Visakhapatnam. Her area of interest is sentiment analysis and text mining. K.Vanitha is currently working as Assistant Professor in the Department of ComputerScience,GIS, GITAM University. Her main areas of research includes Data Mining.