Exploring Government Uses of Social Media Through Twitter Sentiment Analysis
Exploring Government Uses of Social Media Through Twitter Sentiment Analysis
Exploring Government Uses of Social Media Through Twitter Sentiment Analysis
Analysis
ABSTRACT: As social media becomes an important Based, Twitter, Social Media, Social Media Mining, User
platform for organizations to use to interact with users, Engagement, Electronic Government
the ability to understand user opinions in social media
communications has gained increased attention. One of Received: 1 May 2016, Revised 4 June 2016, Accepted 10 June
the most popular approaches for exploring user opinions 2016
is sentiment analysis, which employs natural language
1. Introduction
processing, statistics, or machine learning to extract the
sentiment of a text unit in terms of positive or negative
With both growing popularity and prevalence, social media
attitudes. However, the effectiveness, interpretation, and
is considered a platform on which human opinions,
accuracy of sentiment analysis rely heavily on the context
comments, thoughts, and attitudes are expressed, shared,
in which it is conducted. In this paper, we investigate three exchanged, or even influenced. For example, Twitter users
sentiment analysis techniques for Twitter use by build social relationships with friends and strangers by
governments with their citizens, including a lexicon-based sharing short messages of interests and activities. This
approach, a machine learning-based approach, and a user-generated content on social media has become
hybrid approach. Our results reveal that, while each valuable assets to organizations and businesses, as they
technique is developed based upon different rationales, often contain significant information for better strategies
the results are statistically robust and comparable. The and decision-making. Many businesses, cultural
study provides new insights into sentiment analysis in organizations, and social institutions are leveraging social
the context of government uses of social media. media to achieve their own strategic goals. According to
research that has assessed the social media activity of
Categories and Subject Descriptors the top 100 most valuable global brands, the brands that
H.3.5 [Online Information Services]: Web-based services; were the most socially active saw an 18% increase in
I.2.7 [Natural Language Processing]: Text analysis; H.2.8 their revenue for the previous year, while the least active
[Database Applications]: Data mining experienced a 6% revenue decrease during the same
period [1].
General Terms: Sentiment analysis, social media
One of the most effective approaches for exploring and
Keywords: Sentiment Analysis, Opinion Mining, Lexicon- understanding these opinions is sentiment analysis.
3. Data and Methodology included 10 from the U.S. and 10 from Canada, chosen
with the objective of diversity in both geographic location
For this study, we collected Twitter data from 20 city and population. All re-tweets were considered as normal
government Twitter accounts. The collection period was tweets for this analysis. Table 1 presents a descriptive
from January 1, 2013 to August 25, 2014. The 20 cities summary of the collected data set for the 20 city accounts.
292 Journal of Digital Information Management Volume 14 Number 5 October 2016
The data for the 20 Twitter accounts were retrieved through which contained the actual tweet text. Finally, the retrieved
Twitter Python API’s (get_user_timeline) and included both data were cleansed by removing symbols, punctuation,
tweets and re-tweets made as responses to the special characters, URLs, and numbers for a precise
government accounts. The data collected were saved in sentiment analysis.
the JSON format, done in Python, to retrieve the list of
tweets and save them in a tabular format. The tabular Figure 1 depicts the overall methodology and the flow of
data was used for sentiment analysis of the content field, each analysis step used for this study.
3.1 Sentiment Analysis: Lexicon-Based Techniques 1. The dictionary developed by Taboada et al., which has
To investigate lexicon-based techniques for sentiment been carefully designed and used in the work published
analysis, we adopted a dictionary-matching approach. by Computational Linguistics and has been widely cited
This type of approach uses dictionaries of words annotated [27]. In this dictionary, a comprehensive list of individual
with their semantic orientation, or sentiment, and matches words has been provided with both their sentiment polarity
the text that needs to be analyzed with the dictionary to and strength. To be more specific, the dictionary consists
determine the text’s sentiment label: positive, negative, of a list of 2,827 positive and negative adjectives, such as
or neutral. In other words, the dictionary is used for the priceless (positive), awesome (positive), humiliating
process of assigning a positive, negative, or neutral label (negative), and vicious (negative), a list of 876 positive
to a text to capture the text’s opinion, sentiment, or and negative adverbs, such as flawlessly (positive),
attitude within its context, and in this case, the government perfectly (positive), woefully (negative), and bitterly
use of Twitter. While this method is relatively less involved (negative), a list of 219 positive and negativeinterjections,
with a machine learning or full linguistic analysis, it is such astremendous (positive), incredible (positive),barely
considered a well-performed, robust, and effective (negative), and arguably(negative), a list of 1,550 positive
approach [27]. and negative nouns, such as beauty (positive), pride
(positive), violence (negative), and curse (negative), and a
To implement a rigorous lexicon-based approach, the first list of 1,142 positive and negative verbs, such as succeed
step is to choose a dictionary thatconsists of (positive), amuse (positive), moan (negative), and hinder
acomprehensive list of words with their semanticorientation (negative).
annotated as positive, negative, or neutral.
2. The Valence Aware Dictionary and sEntiment Reasoner
To achieve this goal, in this study, we adopted a combined- (VADER) lexicon, which is specifically attuned to
lexicon approach, where three lexicons were used and sentiment analysis for social media text [28]. With this
weighted for sentiment matching and calculation. This lexicon, the positive, negative, or neutral sentiment of each
approach has the benefits of generating higher accuracy word is weighted based on its semantic meaning, its
and higher confidence in the sentiment analysis results. relationship with nearby texts, whether it is capitalized,
The three adopted lexicons include: and with which punctuation it is associated. These
• Applying the Natural Language Toolkit (NLTK) for stop- • Naïve Bayes: The Naïve Bayes method is a probabilistic
words removal and lemmatization [30]; classifier that is based on Bayes’ theorem with an
• Using Porter Stemmer for stemming [32]. assumption of independence between features. This
classifier uses a maximum likelihood principle to assign
The lexicon-based analysis involves a comparison each unlabelled instance a class and represent features
between the pre-processed tweets/re-tweets and the using vectors [38].
three lexicons respectively. Each pre-processed tweet/
re-tweet corresponding to a certain government account • K-Nearest Neighbors:The K-Nearest Neighbors method
was matched against each lexicon to classify each word is a non-parametric algorithm that assigns an instance to
into positive, negative, or neutral. For each tweet/re-tweet, a class by a majority vote of its neighbors, i.e., the instance
a sentiment score was then calculated based on the is assigned to the class most common among its k
distribution of positive, negative, and neutral words found nearest neighbors.We chose k to be an odd number, 3,
in each lexicon. so that a majority class always exists [40].
3.2 Sentiment Analysis: Machine Learning-Based • Random Forests: The Random Forests method uses
Techniques multiple learning algorithms to obtain better predictive
To examine the robustness of the sentiment analysis results, including classification, regression, and other
results from the lexicon-based technique and further tasks [39]. With Random Forests, a multitude of decision
understand the citizens’ sentiments, we developed a trees are constructed with training data, and the resulting
machine learning-based model for sentiment prediction class is either the mode of the classes (using a
and classification. We used the data mining software, “classification” algorithm) or the mean prediction (using a
Weka, to conduct sentiment analysis on the collected “regression” algorithm) of individual trees.
3.3 Sentiment Analysis: Hybrid Techniques To understand the overall sentiment analysis for all Twitter
To provide a fair and comprehensive comparison of our messages collected using the three techniques and
sentiment analysis techniques, we further expanded this statistically examine the distribution of these sentiments,
study by including a third method, SentiStrength [7], which we first coded the sentiments using the following scheme:
has been described and evaluated in academic articles
(e.g., [41], [5]). We consider it a hybrid technique. 0: neutral sentiment
SentiStrength provides estimates of positive and negative +1: positive sentiment
sentiments in short or even informal texts. A unique feature -1: negative sentiment
of SentiStrength is that it also reports single scale (-4 to
+4) results, which complements our previous methods in The sentiment means and the standard deviations from
which only binary sentiments were identified. these three techniques, respectively, were then calculated.
Table 2 presents the percentages of positive, negative,
Figure 2 provides an architectural view of the three and neutral sentiments from all city accounts, followed
sentiment analysis techniques that were adopted in this by the means and standard deviations of these sentiments
study. given below in Table 3.
@cityofatlanta 23.3 9.0 67.7 18.4 6.4 75.2 20.0 7.0 73.0
@austintexasgav 17.6 8.9 73.5 24.8 5.0 70.2 19.1 3.0 77.9
@notifyboston 15.0 14.5 70.3 25.8 6.8 67.4 20.7 4.0 75.3
@honolulugov 13.8 11.9 75.0 24.3 7.8 67.9 22.5 12.0 65.5
@kcmo 22.7 6.8 70.5 24.3 11.6 64.1 29.0 3.0 68.0
@mesaazgov 20.9 5.7 72.4 31.8 6.5 61.7 19.5 7.0 73.5
@nycgov 15.3 7.9 76.7 30.0 5.0 65.0 18.6 4.0 77.4
@raleighgov 21.0 6.7 72.3 27.0 6.9 66.1 21.5 3.0 69.9
@riversidecagov 25.9 4.7 69.5 17.8 12.5 69.7 27.1 3.0 69.9
@cityofseattle 22.5 9.5 68.0 21.4 8.8 69.8 26.3 12.0 61.7
@cityofcalgary 19.3 10.5 70.2 22.3 7.0 70.7 23.7 8.0 68.3
@cityofedmonton 19.4 10.3 70.3 27.4 4.5 68.1 18.6 12.0 69.4
@hfxgov 15.2 11.0 73.8 25.0 2.3 72.7 11.5 5.0 83.5
@mtl-ville 3.5 3.3 93.2 8.4 2.3 89.3 16.8 10.0 61.5
@ottawacity 16.8 8.2 75.0 16.6 12.7 70.7 28.5 10.0 61.5
@cityofregina 16.7 13.7 69.6 23.9 5.1 71.0 18.1 3.0 78.9
@cityofsurrey 26.4 7.9 65.7 23.0 6.7 70.3 21.1 3.0 75.9
@torontocomms 13.5 9.1 77.5 24.2 3.4 72.4 15.2 4.0 80.8
@cityfvancouver 22.3 9.2 68.5 30.0 2.7 67.3 11.6 5.0 83.4
@cityofwinnipeg 14.4 15.7 69.9 17.3 6.5 76.2 21.3 8.0 70.7
Table 2. Percentages of Positive, Negative, and Neutral Sentiments Using 3 Techniques for 20 City Accounts
To statistically investigate whether the results of the three slogan, along with “The Live Music Capital of the World.”
sentiment analysis techniques differed significantly or not, Austin has the stated goal of being the “best managed
we performed an ANOVA test on the sentiments. These city” in the United States. The city launched Facebook,
results are given in Table 4 and Figure 3. Twitter, and YouTube accounts in 2009.
The ANOVA test shows that, at an aggregate level, the We first randomly selected 10 Twitter messages in
three sentiment analysis techniques, while functioning response to the selected “@austintexasgov” city account.
based on different rationales and algorithms, also provide Table 5 presents these findings, in which the actual
a statistically consistent and robust result. message and the estimated sentiments from all three
techniques are also given.
5. Case Study: The City of Austin, Texas
The results show that for these randomly selected 10 mes-
To further explore how these three sentiment analysis sages, the sentiment predictions using the lexicon-based
techniques perform at a finer level, we chose to focus and approach and the machine-learning approach were iden-
present our analysis for the City of Austin, Texas. Austin tical. There were some slight differences in sentiment pre-
is a mid-sized city of about 800,000 people and is the dictions between SentiStrength and the other two ap-
capital city of the state of Texas. Austin is known for its proaches, specifically for Tweets #1 and #6. If we take a
independent spirit, with “Keep Austin Weird” a prominent closer look at these tweet contents, we can conclude
Table 3. Sentiment Means and Standard Deviations Using 3 Techniques for 20 City Accounts
Source df SS MS F P-value
SA 2 0.06 0.03 7.7841 0.001
Error 57 0.22 0.004
Total 59 0.28
Table 4. One-Way ANOVA Test for the Sentiment Analysis (SA) Techniques
conclude that it is largely because SentiStrength predicts the research period January 1, 2013 to August 25, 2014.
sentiments as more than a binary classification and reports The peaks and valleys in these trends may reveal how
sentiments on a wider (-4 to +4) scale. citizen sentiment changed in line with significant city
events, announcements, and activities. For example, we
We also conducted a sentiment analysis to better noticed a spike in positive sentiments in February of 2014.
understand the trends and patterns for how citizens We found that February was the month in which the Austin
responded to governments’ use of social media—in this city government was promoting the upcoming world-
specific case, Twitter. To achieve this goal, we created famous SXSW (South by Southwest) festival, along with
two visual displays based on the sentiment analysis several other cultural and art events (e.g., “We’re now
results for each city account, namely, the Twitter
accepting applications for #ATX Creative Ambassadors”;
Sentiment Trends and the Comparison Word Cloud. The
“City of Austin announces new public art opportunity at
Twitter Sentiment Trends graph can be used to explore
Montopolis Neighborhood Center”). On the other hand,
the changes in citizen sentiments over time, which may
we noticed a spike in negative sentiments in March of
correspond to unique events, new policies, and important
government announcements. The Comparison Word Cloud 2013, which might have resulted from arguments and
can be a powerful tool to use to understand the discussion discussions about the panellists who were selected for
interests of citizens on Twitter within a given period of the redistricting commission (e.g., “There were actually
time. We chose Austin, Texas (Twitter more women in the pool than men. Very few racial
account:@austintexasgov) as an example to discuss minorities to choose from, though”; “… Hopefully the
these two graphs further. applicant pool for the commission will be more diverse”).
These observations indicate how citizen sentiments can
Figure 4 presents the Twitter sentiment trends for be driven by events, and that the government should value
@austintexasgov by showing the percentages of positive, citizens’ social media responses when making its
negative, and neutral tweets per month, respectively, for decisions and designing its policies.
Finally, Figure 5 represents the word cloud of all tweets comparing these sentiment analysis techniques in the
and re-tweets for @austintexasgov between January 1, context of government use of social media. Our study
2013 and August 25, 2014. The cloudserves as an contributes to the understanding of how sentiment analysis
informative snapshot to understand what topics citizens techniques can perform similarly, or differently, in the given
cared about and became interested in within a given context of government uses of social media. The different
timeframe. interpretations of governmental social media data and of
citizen engagement on social media can greatly affect
6. Conclusions and Limitations policy-making, government-citizen relationships, and
public trust.
In this study, we examined three sentiment analysis
techniques performed on Twitter data in the specific context Our study also suggests how sentiment analysis results
of citizens’ responses to governments’ Twitter posts. can be used to identify the trends and patterns of citi-
These three techniques include a lexicon-based approach, zens’ sentiments driven by events. This finding has two
a machine learning-based approach, and a hybrid implications. First, citizens’ sentiments can indeed be
approach called “SentiStrength,”covering a wide spectrum influenced by city events, activities, announcements, and
of possible sentiment analysis techniques. The selected many more, so it is critical for governments to take into
data provide one of the first attempts to examining and account citizens’ opinions via social media for making