# Exploring Pandemics Events on Twitter by Using Sentiment Analysis and Topic Modelling
## 8 Sentiment Analysis  
In this research, we have combined a lexicon and semi-supervised learning techniques to perform a sentiment analysis. There are no emotion or sentiment labels in our data; therefore, we have used a lexicon to label emotion. Furthermore, we have considered an emotion classifier, based on the National Research Council Canada (NRC) Affect Intensity Lexicon [49], available in Python with the emotion-nrc-affect-lex package [50], that identifies emotions and computes an aggregated score for each emotion. This classifier uses a lexicon that has around 10,000 entries for eight emotions: fear, anger, anticipation, trust, surprise, sadness, disgust, and joy. Specific rules have been defined to label the sentiments: for every tweet and corresponding emotion distribution, we have selected the emotion with the highest weighted emotion score; if there are no emotions, because no word matched, we have assigned the neutral sentence label. According to this approach, each tweet can have a sentiment assigned. Once the sentiments are labelled, we performed semi-supervised learning. The dataset, as shown in Figure 14, has been divided into two parts: the training dataset (80%) and the test dataset (20%). The training data have been used to build the classifier and the testing data are used to measure the performance. Particularly, for the training data, 80% of the labels of the data are removed and the remaining labels are regarded as the ground truth. We have defined the classifiers by considering the labelled training data and using logistic regression (LR), a multinomial Bayes (MNB) model, and random forest (RF) based on the TF-IDF vector. Then, we have measured their performances on our test dataset, which is summarised in Table 3. According to the accuracy value of 0.80, we have selected the logistic regression model. Figure 13: Topic modelling results based on LDA obtained with the pyLDAvis library. We have also applied a self-training approach that belongs to the semi-supervised machine learning algorithms, as it uses a combination of labelled and unlabelled data to train the model. The idea behind the self-training approach consists of:  
* Using the labelled data to train the first supervised model, such as the logistic regression one;
* Using the model to predict the class of the unlabelled data;
* Selecting the tweets that satisfy the predefined criteria (e.g., with a prediction probability of 96% or belonging to the top 10 observations with the highest prediction probability);
* Combining these pseudo-labels with the labelled data;
* Using the labels and pseudo-labels to train a new supervised model;
* Making predictions again and adding the new observations to the pseudo-labelled pool;
* Iterating these steps until no other unlabelled observations satisfy the pseudo-labelling criterion, or when the specified maximum number of iterations is reached;
* Finally, defining an adjusted or improved logistic regression classifier (whose accuracy is 80%) that labels the sentiment of all the observations. Figure 15 shows that fear, trust, and disgust are the three most dominant emotions. In detail, 38.4% of the tweets have the fear emotion to pandemics and 16.5% of the tweets contain the disgust mood. At the same time, there are 20.5% of tweets which express a trust emotion. \begin{table}
\begin{tabular}{c c c c c c c c c c c} \hline \hline
**Emotion** & **Support** & \multicolumn{3}{c}{**LR**} & \multicolumn{3}{c}{**MNB**} & \multicolumn{3}{c}{**BF**} \\  & & **Precision** & **Recall** & **H-Score** & **Precision** & **Recall** &  
Figure 16 shows the sentiment distribution in different pandemic datasets: in cholera, Spanish flu, and yellow fever, fear dominates among the emotions; in Ebola, influenza, tuberculosis, typhus, and Zika, the trust emotion occupies a significant proportion, although fear is the biggest one; in HIV/AIDS, the trust emotion accounts for a larger proportion than fear; and in malaria and swine flu, disgust has the highest frequency, followed by fear and trust.