You are on page 1of 11

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/335471905

Tweep: A System Development to Detect Depression in Twitter Posts

Chapter · January 2020


DOI: 10.1007/978-981-15-0058-9_52

CITATIONS READS

11 1,022

6 authors, including:

Chempaka Seri Siti hafizah Ab hamid


University of Malaya University of Malaya
1 PUBLICATION 11 CITATIONS 60 PUBLICATIONS 1,274 CITATIONS

SEE PROFILE SEE PROFILE

Nor Badrul Anuar Mohd Hafiz Jali


University of Malaya Technical University of Malaysia Malacca
185 PUBLICATIONS 8,375 CITATIONS 101 PUBLICATIONS 443 CITATIONS

SEE PROFILE SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Android malware detection and response View project

Android Botnet Detection And Response System View project

All content following this page was uploaded by Siti hafizah Ab hamid on 27 April 2020.

The user has requested enhancement of the downloaded file.


Depression Status Based on Twitter Posts Using Machine
Learning

Chempaka Seri binti Abdul Razak1, Muhammad Ameer bin Zulkarnain1, Siti Hafizah
binti Ab Hamid1, Badrul Anuar bin Juma’at1, Mohd Zalisham Jali2, Hasni bin Meon3,
1 Fac. Of Computer Sc. & Info. Techno, University of Malaya, Malaysia
2 Universiti Sains Islam Malaysia, Malaysia
3 Universiti Selangor, Malaysia

Abstract. According to WHO, depression becomes a common mental disorder


that affects more than 300 million people all around the world. One of the con-
tributing factors of depression is the usage of social media. Studies found that
social media platforms have a negative effect to its users caused from cyberbul-
lying that include body shaming and racism or negative posts also can affect any
users that can cause them to reflect to their prior memories that can cause anxiety
and lead to depression. The main objective of this study is to develop an applica-
tion that analyzes Twitter users’ posts for detecting personal depression attitude
using Machine Learning. By having the application, the users know their past
emotion condition which helps them to take necessary action if required.

Keywords: Depression, Twitter, Machine Learning, Emotion

1 Introduction

Depression becomes a leading cause of morbidity related to emotional, psychological


and social well-being of mental disorder. It is a serious health condition when a person
experience long-lasting with moderate and severe intensity depression or known as de-
pressive episode. According to the World Health Organization (WHO), 300 million
people of all ages suffer from depression. At its worst, depression can lead to suicide
which approximately 800 000 people die to suicide every year around the world. Sui-
cide is known as the second leading cause of death for people at the age 15 – 29 years
old.

Social media acts as a tool in public health providing instant communication in cross
generation. The social media applications for instance; Facebook, Instagram, and Twit-
ter encourage users to share their experiences, opinions, knowledge, and locations. In
addition, the applications provide a gigantic corpus of data from different regions, eco-
nomic climates, and languages which gives insights from political sentiment to public
health situation (Boydstun et al., 2013), (Aramaki, Maskawa, and Morita, 2011).
2

Among all social media platforms, Twitter is the only microblogging medium that al-
lows users to post short messages.

2 Related Works

Social media acts as a tool in public health providing instant communication in cross
generation. The social media applications for instance; Facebook, Instagram, and Twit-
ter encourage users to share their experiences, opinions, knowledge, and locations. In
addition, the applications provide a gigantic corpus of data from different regions, eco-
nomic climates, and languages which gives insights from political sentiment to public
health situation (Boydstun et al., 2013), (Aramaki, Maskawa, and Morita, 2011).
Among all social media platforms, Twitter is the only microblogging medium that al-
lows users to post short messages.

Twitter is one of the most popular social networking sites with almost 326 million ac-
tive users and 90 mil- lion tweets publicly broadcasted to a large audience [1]. Many
researchers have successfully utilized Twitter data as a source of insights into the epi-
demiology of emotions, depression and other mental disorders of the users who tweet.
De Choudhury et al. [2] used linguistic features to train a classifier to examine Twitter
posts that indicated depression among young mothers. Coppersmith et al. [3] looked
for tweets that explicitly stated “I was just diagnosed with depression” sentences. Pre-
otiuc-Pietroi et al. [4] applied broader textual features such as LIWC, LDA and frequent
1-3 grams on the Twitter data to examine the personality of the users with self- declared
post-traumatic stress (PTSD) disorders.. Resnik et al. [5] proved that the LDA model
can uncover a meaningful and potentially useful latent structure for the automatic iden-
tification of important topics for depression detection. Bentoni et al. [6] demonstrated
the effectiveness of multi-task learning (MTL) models on detecting mental health dis-
orders without the users clinical history. He used feed-forward perceptron and feed-
forward multi-task models trained to predict each task separately as well as to predict a
set of conditions simultaneously. Reece et al. [7] found out that the first stage of de-
pression may be detectable from the users Twitter posts several months prior to his
system analysis with 0.87 AUC of performance probability.

Table below shows a comparison of techniques used for all the research papers. All
related works used Twitter data to analyse and detect depression or mental disorder
using different methods of Machine Learning. However, they limit to English Language
and very specific domain or target users.

Table 1. Comparison of Technique Used

Features Methods Best Results Reference


LIWC, sentiment, time series RF AUC 0.87 Reece et al [7]
LIWC, n- grams, topic model- LR AUC 0.85 Preotiuc- Pietro
ling, sentiment et al [4]
N-grams Neural Network AUC 0.76 Bentoni et al [6]
3

3 Methodology

3.1 Data Preprocessing


The tweets are extracted using Python. The first step is data cleaning. The tweets are
extracted in JSON. Quotes, extra spacing, and symbols are removed from the tweets
and the tweets are stores in the database.

3.2 Text Classification Techniques

The text classification techniques are divided into Machine Learning (ML) approach,
Lexicon-Based (LB) approach and Hybrid approach. The ML approach applies for the
ML algorithms and uses linguistic features. The LB approach relies on the sentiment
lexicon, a collection of known and precompiled sentiment terms. The LB approach is
divided into dictionary-based approach and corpus-based approach which use statistical
or semantic methods to find sentiment polarity. The Hybrid approach combines both
approaches and is very common with sentiment lexicons playing a key role in the ma-
jority of the methods.

The system employs a Machine Learning approach (Naïve Bayes), Lexicon-based ap-
proach (Natural Language Processing (NLP) technique) and Deep Learning approach
(Feedforward Neural Network).

Naïve Bayes Classifier


The Naïve Bayes classifier is the simplest and most commonly used classifier. Naïve
Bayes classification model computes the posterior probability of a class, based on the
distribution of the words in the document. The model works with the BOWs feature
extraction which ignores the position of the word in the document. It uses Bayes The-
orem to predict the probability that a given feature set belongs to a particular label.
P(label)∗𝑃(𝑓𝑒𝑎𝑡𝑢𝑟𝑒𝑠|𝑙𝑎𝑏𝑒𝑙)
𝑃(𝑙𝑎𝑏𝑒𝑙|𝑓𝑒𝑎𝑡𝑢𝑟𝑒𝑠) = (1)
P(features)

P(label) is the prior probability of a label or the likelihood that a random feature set the
label. P(features|label) is the prior probability that a given feature set is being classified
as a label. P(features) is the prior probability that a given feature set is occurred. Given
the Naïve Bayes assumption which states that all features are independent, the equation
could be rewritten as follows:
P(label)∗P(𝑓1|𝑙𝑎𝑏𝑒𝑙)∗… …∗P(fn|label)
𝑃(𝑙𝑎𝑏𝑒𝑙|𝑓𝑒𝑎𝑡𝑢𝑟𝑒𝑠) = (2)
P(features)

An improved NB classifier was proposed by Kang and Yoo [8] to solve the problem of
the tendency for the positive classification accuracy to appear up to approximately 10%
higher than the negative classification accuracy. This creates a problem of decreasing
4

the average accuracy when the accuracies of the two classes are expressed as an average
value. They showed that using this algorithm with restaurant reviews narrowed the gap
between the positive accuracy and the negative accuracy compared to Naïve Bayes and
Support Vector Machine. The accuracy is improved in recall and precision compared
to both Naïve Bayes and Support Vector Machine.

Natural Language Processing (NLP)

Natural Language Processing (NLP) techniques are sometimes used with the lexicon-
based approach to find the syntactical structure and help in finding the semantic rela-
tions. Moreo and Romero [9] have used NLP techniques as preprocessing stage before
they used their proposed lexicon- based SA algorithm. Their proposed system consists
of an automatic focus detection module and a sentiment analysis module capable of
assessing user opinions of topics in news items which use a taxonomy- lexicon that is
specifically designed for news analysis. Their results were promising in scenarios
where colloquial language predominates.

The approach for SA presented by Caro and Grella [10] was based on a deep NLP
analysis of the sentences, using a dependency parsing as a pre-processing step. Their
SA algorithm relied on the concept of Sentiment Propagation, which assumed that each
linguistic element like a noun, a verb, etc. can have an intrinsic value of sentiment that
is propagated through the syntactic structure of the parsed sentence. They presented a
set of syntactic-based rules that aimed to cover a significant part of the sentiment sali-
ence expressed by a text. They proposed a data visualization system in which they
needed to filter out some data objects or to contextualize the data so that only the infor-
mation relevant to a user query is shown to the user. In order to accomplish that, they
presented a context- based method to visualize opinions by measuring the distance, in
the textual appraisals, between the query and the polarity of the words contained in the
texts themselves. They extended their algorithm by computing the context-based polar-
ity scores. Their approach approved high efficiency after applying it on a manual corpus
of 100 restaurants reviews.

Min and Park [11] have used NLP from a different perspective. They used NLP tech-
niques to identify tense and time expressions along with mining techniques and a rank-
ing algorithm. Their proposed metric has two parameters that capture time expressions
related to the use of products and product entities over different purchasing time peri-
ods. They identified important linguistic clues for the parameters through an experiment
with crawled review data, with the aid of NLP techniques.

Feedforward Neural Network

A feedforward neural network is a type of artificial neural network com- posed of a


collection of linked computational units, often referred to as nodes or neurons, that are
5

arranged in multiple layers, where information in the resulting network of units is prop-
agated forward from one layer to another, from an initial input layer, to one or more
hidden layers, and then finally to an output layer, in a non-cyclic fashion. In this study,
the initial layer consisted of the inputs, represented as a “bag of words”, or a vector of
zeros and ones, with each value in the vector representing the presence or absence of a
unique token. These inputs are then multiplied by a vector of weights, which are the
parameters for the network that are trained through a learning process. The output pro-
duced by a hidden layer, or a layer between the input and output layers, is the result of
the application of an activation function to the values from the previous layer.

4 System Requirement

4.1 Functional System Requirement

The functional requirement describes what the system will do. It is based on the view-
point of the target users.

1. The system shall allow the user and the administrator to login to the system via Twit-
ter.
2. The system shall be able to display the user’s followers and following profiles.
3. The system shall be able the user to display the user, his or her followers, and his or
her following tweets.
4. The system shall be able to visualise the analysed data in chart and table manner.
5. The sentiment module shall be able to receive Twitter data from the Twitter API
6. The sentiment module shall be able to calculate tweets sentiment score
7. The system shall allow the administrator to view users that have registered to the
system
8. The system shall allow the administrator to delete registered user from the system

4.2 Non-functional System Requirement


While functional requirements describe what a system application should do, non-func-
tional requirements define how well it needs to function and most importantly, they
shape the quality of the final product.

Interoperability
1. The system is able to connect to Twitter database via the Twitter API
2. The system is able to communicate to three Python Application via REST API
6

5 System Development

Figure below shows the Use Case Diagram for the system. The user will login to the
system and they are able to analyze their tweet sentiment. The user also able to analyze
their followers or following tweets sentiment.

Fig. 1. Use Case Diagram of the System

The system will send the tweets in JSON to be analyzed and stored the results in the
database. The tweets will be analyzed in all three models. The system will return the
predicted sentiments which are Positive, Negative or Neutral. When the system returns
two Positive results and one Negative or Neutral result, the system will take the Positive
predicted sentiment as for the Overall Predicted Sentiment, same as for two Negative
results and two Neutral results.

Fig. 2. Sequence Diagram of the System


7

Both NLP model and ML model are not compatible to Malay tweets and tweets that
have more than one language which then predicted the tweets are Neutral. But for DL
model, the system can predict tweet in Malay and tweet that have more than one lan-
guage. For this result, when the system finds that both NLP and ML predicted the tweets
are neutral, it will then ignore both model results and take the DL model results. Figure
3 until Figure 6 shows the interface of the system.

Fig. 3. Percentage of User’s Tweet

Fig. 4. Number of Positive and Negative tweets of a user for each month (2019)
8

Fig. 5. Number of Positive and Negative tweets of a user for each month (2018)

6 Results

After extracting the data, this resulted in having 10,882 processed tweets, combined
English and Malay tweets. The tweets are then analyzed using three different tech-
niques which are Naïve Bayes Classifier technique, NLP techniques and Deep Learning
technique.
Table 2. Accuracy Score based on Techniques
Techniques Accuracy Score
Naïve Bayes 0.68
NLP 0.64
Feedforward Neural Network 0.72

For Naïve Bayes technique, it gives an accuracy score of 0.68 meanwhile for the NLP
technique produce an accuracy score of 0.64. It is found that both Naïve Bayes tech-
niques and NLP technique works well with English tweet, but it is not compatible to
Malay tweets as the corpus used is not in Malay. As for Deep Learning technique, the
accuracy score for the model is 0.72 which is the highest among of all the other tech-
niques. the model able to learn recognize the sentiments for Malay tweets, but the ac-
curacy of the model needs to be improved as more data need to be extracted.

Naïve Bayes Classifier technique and NLP technique gives a neutral value for Malay
tweets and combined tweets that consist more than one language in a tweet. Hence, we
can conclude that the model doesn’t compatible for other languages than English
tweets. As for Deep Learning technique, it manages to analyze on the Malay tweets and
tweets that have more than one language. Apart from that, the model doesn’t work well
with negation tweets as it produces a False Positive or False Negative result.
9

After the sentiment of each user tweets is calculated, the depression percentage is then
calculated based from the total positive and total negative tweets. If the users have a
high percentage of positive tweets, it will classify the users as an optimistic person that
implies the user is no depression related. Meanwhile, users that have a high percentage
of negative tweets, it will classify the users as an optimistic person that can implies the
users might be depression related.

7 Conclusion

Social media have gain insight that turn into signals that is tied to mental health issues
which have an increate rate in research interest. However, most of the research is done
in English. Our study demonstrates that a wide data collection is first used in research
that is done on English social media data with commonly used machine learning clas-
sifiers that is adequate in discriminate depressed social media users from a random
group. Furthermore, it demonstrates that this process is at least effective with Malay
data as it proven to be in the past studies with English data. Using a Python script to
bypass the limitations of the Twitter API while still leveraging publicly available data,
the sentiment of each tweets is calculated for each user. Various techniques are used to
calculate the sentiment of each tweets that are Naïve Bayes classifier, Natural Language
Processing and Deep Learning. However, all of the techniques are not further optimized
that could have a higher accuracy for Malay tweets. For future research, Malaysian is
well-known for having more than one language in a tweet which is comfortably called
Manglish which effect the results. Tweets that contain different number of punctuation
marks, words containing all capital letters (e.g. SUKA), words with character flooding
(e.g. sukaaaa), emojis, and negation words may affect the results. Next, more accurate
techniques, such as robust tokenization and stemming methods or any reliable methods
could improve the quality of the input text. Finally, tweets that contain words that have
a negative meaning but brings a positive vibe (e.g. savage, which can be translated as
someone who is unpredictable) to the community should be taken in context as it actu-
ally has a different meaning toward that community

References
1. T. S. Portal Statistics and Studies. (2019). Social Media Usage Worldwide. [Online]. Avail-
able: https://www.statista.com/statistics/272014/global- social-networks- ranked-by-num-
ber-of-users/
2. M. De Choudhury, S. Counts, and E. Horvitz, ‘‘Predicting postpartum changes in emotion
and behavior via social media,’’ in Proc. SIGCHI Conf. Hum. Factors Comput. Syst., Apr.
2013, pp. 3267–3276.
3. G. Coppersmith, M. Dredze, C. Harman, and K. Hollingshead, ‘‘From ADHD to SAD: An-
alyzing the language of mental health on twitter through self-reported diagnoses,’’ in Proc.
2nd Workshop Comput. Linguistics Clin. Psychol. Linguistic Signal Clin. Reality, 2015, pp.
1–10.
4. D. Preotiuc-Pietro et al., ‘‘The role of personality, age, and gender in tweeting about mental
illness,’’ in Proc. 2nd Workshop Comput. Linguistics Clin. Psychol. Linguistic Signal Clin.
Reality, 2015, pp. 21– 30.
10

5. P. Resnik, W. Armstrong, L. Claudino, T. Nguyen, V.-A. Nguyen, and J. Boyd-Graber,


‘‘Beyond LDA: Exploring supervised topic modeling for depression-related language in
twitter,’’ in Proc. 2nd Workshop Com- put. Linguistics Clin. Psychol. Linguistic Signal Clin.
Reality, 2015, pp. 99–107.
6. A. Benton, M. Mitchell, and D. Hovy. (2017). ‘‘Multi-task learning for mental health using
social media text.’’ [Online]. Available: https://arxiv.org/abs/1712.03538
7. A. G. Reece, A. J. Reagan, K. L. Lix, P. S. Dodds, C. M. Danforth, and E. J. Langer, ‘‘Fore-
casting the onset and course of mental illness with twitter data,’’ Sci. Rep., vol. 7, no. 1, p.
13006, Oct. 2017.
8. Kang, H., Yoo, S.J., & Han, D. (2012). Senti-lexicon and improved Naïve Bayes algorithms
for sentiment analysis of restaurant reviews. Expert Syst. Appl., 39, 6000-6010.
9. A. Moreo, M. Romero, J.L. Castro, and J.M. Zurita. 2012. Lexicon-based Comments-ori-
ented News Sentiment Analyzer system. Expert Syst. Appl.39, 10 (August 2012), 9166-
9180. DOI: https://doi.org/10.1016/j.eswa.2012.02.057
10. Caro, L.D., & Grella, M. (2013). Sentiment analysis via dependency parsing. Computer
Standards & Interfaces, 35, 442-453.
11. Min Hey-Jin, Park Jong C. Identifying helpful review based on customer’s mention about
experiences. Expert Syst Appl 2012;39:11830-8

View publication stats

You might also like