Sentiment Analysis in Social Networks Using Social Spider Optimization Algorithm

: In this study, a new swarm intelligence-based algorithm called Social Spider Algorithm (SSA), which is based on a simulation of the collaborative behaviours of spiders, was adapted for the first time for sentiment analysis (SA) within data obtained from Twitter. The SA problem was modelled as a search problem, with datasets considered as the search space and SSA modelled as a search strategy by determining an appropriate encoding scheme and objective function. The success of the SSA was compared with different Machine Learning (ML) algorithms within the same real datasets based on different metrics. Although this study is the first usage of SSA for the SA problem and there is no optimization for it, the attained results were promising and could provide new direction to related research about the use of optimized different artificial intelligence search algorithms for these types of online social network analysis problems. This study also introduced a new application domain for the optimization algorithms.


INTRODUCTION
SA is the contextual mining of text in determining the attitude of a writer based on the language he uses regarding a specific topic or product. The increasing use of social networks has facilitated the communication needs of people, and has also led to the formation of other needs. The opportunity to communicate with many people reveals the need to understand and analyse ideas from different people. Individuals have the need to make certain decisions or to reach certain results by understanding the feelings and thoughts of those they communicate with through analysing their emotions and thoughts. This need has led to the emergence of SA, which can be performed on all kinds of texts, but it is predominantly to form an idea about a specific topic. Emotional analysis is made possible by taking instant opinions from millions of people by utilizing social network data. The key work of the analyst is to analyse existing data in these networks and to produce meaningful results from the raw data. However, it would not be possible to perform manual analysis of this data due to its colossal volume that exceeds even gigabytes [1].
Academic studies on SA are currently increasing. Elliott [2], Ortony et al. [3], and recently Stevenson et al. [4] analysed the number frequency of words in performing opinion mining with primitive SA methods. Nalcakan et al. conducted an SA study by collecting Twitter comments from electronics giants, and attempted to elicit information about the companies by using various ML algorithms in their study [5]. Dumanli et al. commented on the news reported on Twitter by conducting an SA study that evaluated the most interactive news agencies based on relevant Twitter comments [6]. Szomszor et al. conducted an SA study to determine the prevalence of epidemics [7]. Akba et al. performed an SA study on a film dataset with feature extraction algorithms and Support Vector Machines with completely unsupervised ML techniques, and achieved an approximate 84% level of success [8]. In a study performed by Paroubek et al., microblogs were used for SA and opinion mining [9]. With the aid of microblogs, comments were used by different people to express their thoughts on various subjects. The n-gram method was used for the inference of quality in the study, and the best result was obtained using bigram. SA using Konstanz Information Miner in social networks was introduced in [10]. A review of SA and opinion mining algorithms can be found in [11].
In recent years, studies on SA have continued to increase without slowing down. Zhou et al. examined the relationship between social networks and relationship networks using text-mining techniques. They analysed the correlation relationship between the two networks in their study, using customer comments [12]. Basiri et al. used deep learning approaches in their SA study. They conducted SA study on eight different dataset. They achieved an accuracy of 93% with the attention-based model they suggested [13]. Behare et al. worked on social big data for SA. They suggested CNN and LSTM models for SA from customer comments. At the same time, they compared the success of ML algorithms with the model they proposed [14]. In their study on three different datasets, they obtained the highest accuracy value as 95%. Guixian et al. completed SA work on comments. They proposed the BiLSTM method in their study using various deep learning and ML techniques. With the method they suggested, they obtained 92% recall value [15]. Naseem et al. conducted SA studies on four different experiments with transformer based BERT model [16]. They achieved 96% success with the method they suggested on the data of three different airline companies. They also compared the success of their proposed method with different ML algorithms. Nassif et al. conducted an SA study using different methods on the Arabic dataset. In the study, they examined different ML and deep learning models in detail. In addition, the literature for SA studies was analysed in depth. Inference was concluded on choosing the most suitable model for the Arabic dataset. They concluded that the CNN model is suitable for their SA studies [17].
Many animal and insect groups such as ant colonies, fish shoals, bear sleuths, and termite colonies have shown intelligent behaviours in their collective relations, and this behaviour in nature has drawn the attention of academic researchers. The collective behaviour of insects and other animals is known as swarm intelligence. The artificial intelligence branch of Swarm Intelligence is a complex and interactive method of dealing with collective behaviours as in a swarm. Bonabeau described swarm intelligence as "inspired by the collective behaviour of other animal communities and social insect colonies while defining any algorithm or attempting to design a common problemsolving device" [18]. Swarm intelligence methods have many advantages such as speed, parallelism, fault tolerance, modularity, autonomy, adaptation, and scalability [19].
The Particle Swarm Optimization (PSO) algorithm uses social behaviours such as bird flu and fish schooling [20]. Artificial Bee Colony (ABC) is a cooperative behaviour technique that mimics bee colonies [21]. The Bacterial Foraging Optimization Algorithm uses the behaviour of bacterial social gatherer [22]. The Krill Herd method is a simulation of the herd behaviour of these crustaceans [23]. The Cuckoo Optimization Algorithm is based on the lifestyle of the cuckoo bird [24]. Firefly algorithm is based mainly on social behaviours such as the mating behaviours of the firefly insects [25].
The aim of the current study is to adapt and propose an SSA for SA and opinion mining problems working within online social network data, with a new model for SA proposed that uses SSA with Twitter data. Opinion mining and the SA problem were considered as search problems, and datasets as the search space. As a result, SSA was modelled as the search strategy for the first time by determining appropriate encoding scheme and objective function. The attained results from the SSA were compared with ML methods found in the literature, and the results examined in detail. Inferences were then suggested to improve the proposed method.
It is hoped that the current study will be regarded as a reference work in the literature, since it uses an optimization-based approach to SA and opinion mining studies. Researchers on text mining, social networking analysts, and especially conducting optimization studies can use and enhance the methods proposed in this study for different types of social network analysis problems in order to achieve more efficient results.

SOCIAL SPIDER OPTIMIZATION ALGORITHM (SSA) 2.1 Biological Structure of SSA
A social spider colony consists of members and commercial networks. Members are categorized as male and female. Social spiders have a predominantly femalebased population [26,27]. Some studies show that the number of male spiders barely reaches 30% of the total colony [28,29]. Depending on their gender, members of the colony perform different activities such as building and maintaining commercial networks for social communication and development. Interaction between members takes place both directly and indirectly [30]. Direct interaction implies the exchange of fluids, such as in reproduction or other bodily interactions. Indirect interaction is the core of the commercial network communication, where information transmission is key [31,32].
Colony levels are generated as a result of internal interaction, despite complexity existing among all colony members in a global-style business association [33]. Such internal interactions include the simple behavioural sequence followed by each spider in the colony. Behavioral rules are divided into two classes, as social interaction (cooperative behaviour) and mating [34].
Mating is an important process in social spider colonies, and is initiated by the dominant females and male members. In this case, a dominant male spider mates to produce dominant offspring, if one or more female members are located within a certain area [35,36].

Mathematical Model and Optimization Algorithm
The SSA is a population-based intelligent metaheuristic technique [37]. The search field is considered a common network and the position of a spider represents the optimal solution. An interesting feature of social spiders is the female-oriented population. The female spiders N f are randomly selected in the range of 65-90% of the overall colony population N. For this reason, N f is calculated as shown in Eq. (1).
where rand is a random number between 0 and 1. The number of male spiders N m is calculated in Eq. (2) [37].
Each spider takes a weight depending on its fitness. This weight is calculated in Eq. (3).
Here, fitness i is the fitness value of each spider and w i is calculated using Eq. (3) by evaluating the positions of all spiders, for i = 1, 2, 3, ..., N, worst and best values are found by scanning the entire population.
The common network (search field) is used as a mechanism for communicating information. The information is coded as small vibrations and depends on the distance between the weights and the spider that produces them. This relationship is shown in Eq. (4) [37,38].
Here, d ij is the Euclidean distance between i-th and jth spider, and three special relationships can be considered.
Vibration Vibc i is calculated according to Eq. (5). Based on information transmitted by c, the individual is perceived by i-th individual with two important characteristics. It is the nearest individual to i, and it has a greater weight (w c > w i ), as shown in Fig. 1a.
Vibration Vibf i is calculated according to Eq. (7). As a result of the information transferred by f, the i-th individual is the closest to female individual f, as shown in Fig. 1c.
The pulling or pushing action of the other spiders varies according to their vibrations spread over the common network, as shown in Eq. (8) [37].
r m , β, α, σ, and γ are uniform random numbers between (0, 1). Here, f i (t+1) is expressed as the standard for the position of the i-th female spider at the time of step t + 1. s c indicates the nearest member to i with a greater weight value. s b represents the best member among the entire population.
Non-dominant male spiders tend to concentrate as a male population in the centre of the colony in a strategy to exploit resources wasted by the dominant males. This situation is expressed in Eq. (9).  Here, s f represents i-th female spider nearest to the male spider. m i (t+1) is the position of i-th spider in step t+1.
Calculated according to Eq. (10), r is taken as the radius. If a female member is found dominant over the male spider in r, it will mate and produce new offspring. Here, n (the number of variables to be optimized) is the size of the problem. p j high and p j low are the standard for upper and lower bounds. After the new spider has been created, it is compared to the best spider. If the new spider is better, the previously best spider is replaced by the new one. The general structure of the SSA is shown in Alg. (1).

SA in Social Networks
What others think is often an important roadmap in the human decision-making process. The most important characteristic of the social network structure is two-way communication, in other words, interaction. Today, it is no longer enough to read a book whilst sat in a corner. In addition, we are expecting to interact with and influence our surroundings through our collective logic. Humans have switched from newspapers, books, and magazines as sources of data to mobile phones, the Internet, and social media platforms, which we refer to as new communication environments. Information has therefore become instantly available, extensive, and almost universally reachable [39].
In recent years, social networks have become a major source of data for the SA, along with the increased sharing of ideas on the Internet. It is important for researchers, as well as the production and service sectors, to understand what people think about a particular person, service or topic, what they generally like and dislike, what they need the most, and what is currently trending [40].
We should be able to adapt to the information on social networks and its pace, and should be able to improve our capabilities in line with these requirements. The most efficient way of achieving this development is through an individual developmental strategy that focuses on learning within social networks [41,42].

SA APPLICATION 4.1 Collection of Data
The current study utilizes the Sentiment140 dataset, which was created by Alec et al. with approximately 1.6 million Twitter data items. These data consist of prelabelled data as either negative or positive. Tagging uses emoji in the Twitter data. Where there is the "" expression in the Twitter data, it is tagged as positive. On the contrary, where there is the "" expression the data is labelled as negative. In this study, a total of 12000 Twitter data items tweets taken from the Sentiment140 dataset were used to create six different experimental sets. These experimental sets were constructed as balanced or unbalanced datasets according to their label numbers. Each experimental set consists of 2000 Twitter data items. This is described in further detail in Subsection 4.4 for each experimental set.

Use of Machine Learning Techniques
Before using ML algorithms, Natural Language Processing (NLP) techniques were applied to the Twitter data tweets. Text pre-processing steps were performed using NLP techniques that consisted of punctuation deletion, number filtering, case conversion, n-char filtering, stop word filtering, bag-of-words, and creating a document vector. After completion of the text preprocessing steps, Support Vector Machine (SVM), Decision Tree, k Nearest Neighbour (kNN), and Naive Bayes algorithms, which are the most used ML algorithms reported in the literature, were then applied.

Use of SSA
In this subsection, SSA was applied to the document vector created by using NLP techniques.

Setting the SSA Initial Parameters
The initial parameters for the first experiment set of the SSA are presented in Tab. 1. For the first set of experiments, 42 features were extracted after the NLP steps. Therefore, the dimension value for SSA was set to 42. The total number of experiments for each dataset was set to 30, and the maximum number of iterations for each experiment was set to 1000. At the end of the 30 trials, the best experiment result was accepted as the final solution. The number of spiders (i.e., the population) in the SSA for the SA study was set at 30. Weights between 0 and 1 were assigned to each spider. At the end of the next iteration, the weights of the spiders were then updated. The spider with the best level of fitness in each iteration was considered as the best solution for that iteration. For each dataset, only the number of dimensions varied in accordance with the number of features. All other parameters remained constant.

Adjustment of the Fitness Function
The fitness function was designed to obtain a model with the best objective value for both negative and positive training data in each dataset. After the models that best represented the negative data and positive data were established, verification was performed on the test data. In this process, the fitness value is calculated using Eq. (11), and considers many different objectives.
a 1 , a 2 , a 3 , and a 4 are random numbers range (0, 1) whose sum is 1. In the fitness function, the a 1 value is expected to be selected as high if the accuracy value is high; the a 2 value is expected to be high if the precision value is high; and the a 3 value is expected to be selected as high if the sensitivity value is high. It is also expected that the a 4 value should be selected as high if it is desired to return a high selectivity value. In using this fitness function, a multi-objective optimization process was designed. In the current study, the values were set as a 1 = 0,4; a 2 = 0,2; a 3 = 0,2 and a 4 = 0,2 for all of the experimental datasets. The TP was increased by 1 when the predicted and actual results were both positive. The TN refers to the situation in which the predicted and actual results were both negative. The FP indicates a negative predicted result and a positive actual result. The FN indicates a positive predicted result and a negative actual result. This method that was applied for the purposes of accuracy analysis is detailed further in Tab. 2.
The confusion matrix is used for the correctness of the model created using the SSA. Accuracy, sensitivity, precision, and selectivity values are calculated as shown in Eq. (12). The attained accuracy, sensitivity, precision, and selectivity values were computed in each iteration to obtain the model with the best fitness. Models with the best fitness representing positive and negative data were used for validation of the test data. Each test data were compared with both the negative and positive model using the Jaccard similarity. If the class with the class tag is more similar, it is assumed that it belongs to the class that has high similarity to the test data of the Twitter test. Accuracy, sensitivity, sensitivity, and selectivity values were calculated from the test data and the performance of the model was calculated. These operations were performed separately on six different datasets.
SSA was developed in MATLAB for SA. First, by running the algorithm, the 42-dimensional array of numbers from 0 to 1 generated for the first dataset was converted into bit-sequence format consisting of 0's and 1's with the rounding function. Tab. 3 shows an example of a document matrix created using NLP techniques. Tab. 4 shows an example of a positive spider model randomly generated using the SSA, and Tab. 5 shows an example of a negative spider model generated randomly using the SSA.
Tab. 4 and Tab. 5 show 42 random numerical values from 0 to 1 in the representative positive and negative spider model for the first dataset. Prior to the fitness function being executed, rounding was performed with the help of the rounding function to convert the form to 0's and 1's. To find the most appropriate model to represent positive and negative data, each candidate solution in the population of each iteration of the SSA was compared with each training data using one-by-one similarity computation. Whilst there are many similarity measures such as Cosine's Similarity Method, Jaccard Similarity Method, Tanimoto Method, and Dice Similarity Index, the current study applied the Jaccard similarity index to calculate the similarity criterion, as shown in Eq. (13).
The similarity criterion for all datasets was calculated as 0,5. With this method, an estimate of which data was labelled positive or negative was made. Following the estimated tagging, accuracy analysis was performed by comparing the actual class label and the estimated class label. This was performed separately to find the best model to represent both the positive and negative data.

Evaluation and Conclusion
In the SA, a classification study was performed on Twitter data using ML techniques and SSA. The characteristics of the experimental sets used in this part of the study and the success of the SSA and ML techniques on these experimental sets were examined. Tab. 6 shows the success of the results of the first experiment. The accuracy, precision, sensitivity, and selectivity values obtained from the five different methods used in this table are detailed in the table.
The first experiment set consisted of 2000 Twitter data items, split equally as 1000 negative and 1000 positive labelled data. The word count for each Twitter data item was set to exceed 20. Values less than 20 were disregarded as a feature when creating the document vector. If there was no word in the repetition of more than 20 words in the Twitter data item, this item consisted of a 0 matrix. In order for the document vector of any Twitter data item to be generated, at least one of the words it contains must be above the specified frequency value. A total of 42 features were extracted in the first experiment set. Accordingly, the dimension parameter of the SSA was set to 42. In total, 1075 document vectors were created, with 72% used for training purposes and 28% for testing. This value was kept constant for all algorithms and experiment sets. The order of performance of the algorithms used for the first experiment set is presented in Tab. 7.
In the first set of experiments, the best accuracy value and the best precision value were attained by SSA. With its 65.2% accuracy value, SSA obtained superior values compared to other algorithms. Moreover, with 68.1% precision value, SSA produced superior results than other ML algorithms. In addition, the highest sensitivity value and the highest selectivity value were obtained by kNN. Tab. 8 shows the success of the results of the second experiment. The accuracy, precision, sensitivity, and selectivity values obtained with five different methods are presented in this table. The second experiment set consisted of 2000 Twitter data 1499 of which are labelled negative and 501 of which are labelled positive. Since a total of 41 features were extracted from the second dataset, the dimension parameter of SSA was set to 41. A total of 1116 document vectors were created. In Tab. 9, the order of accuracy, precision, sensitivity, and selectivity of the results obtained are presented. Table 9 Sorting the algorithms used for Experiment Set 2 Accuracy SVM > Decision Tree > kNN > Naive Bayes > SSA Precision kNN > SVM = Decision Tree > SSA > Naive Bayes Sensitivity Naive Bayes > SVM > Decision Tree > kNN > SSA Selectivity Naive Bayes > SSA > SVM >Decision Tree > kNN In the second experiment set, the best accuracy was attained by SVM, the best precision was obtained from kNN, and the highest sensitivity value and the highest selectivity value were obtained by Naive Bayes. Tab. 10 lists the performance values attained from the algorithms calculated in the third experiment set. A total of 2000 Twitter data items were used for the third experiment set, with 1160 labelled as negative and 840 as positive. A total of 46 features were extracted in the third experiment set, and the dimension parameter of the SSA was set to 46. In total, 1161 document vectors were created. The performance order of the algorithms obtained from the third experiment set is presented in Tab. 11. In the third set of experiments, the best accuracy value and the highest sensitivity value were attained by SVM, the best precision value was obtained by SSA, and the highest selectivity value was achieved by kNN. However, kNN ranked last for the third experiment in all other quality metrics except the selectivity value. With its 65,5% precision value, SSA produced superior result than other ML algorithms for the third experiment.The performance values obtained from the algorithms for the fourth dataset are presented in Tab. 12. A total of 2000 Twitter dataset items formed the fourth experimental set with 492 negative and 1508 positive labels. For a total of 45 features were extracted from the fourth dataset, the dimension parameter of SSA was set to 45. In total, 1351 document vectors were created. The order of performance of the algorithms according to the fourth experiment set is presented in Tab. 13. In the fourth set of experiments, the best accuracy and selectivity value were obtained with SVM, the best sensitivity value was attained from SSA, and the best precision was obtained from kNN. SSA attained the highest success for the fourth experiment with a sensitivity value of 82,6%.
Tab. 14 shows the success of the results of the fifth experiment set. The accuracy, precision, sensitivity, and selectivity values obtained from five different methods used are detailed in this table. The fifth experiment set consisted of 2000 Twitter data items, with 495 labelled as negative and 1505 as positive. A total of 54 features were extracted from the fifth dataset, and the dimension parameter of the SSA was set to 54. In total, 1418 document vectors were created. The order of performance of the algorithms used for the fifth dataset are presented in Tab. 15. In the fifth set of experiments, SSA performed the best in terms of selectivity and accuracy values. However, kNN was better in terms of precision and Naive Bayes was better according to the sensitivity values obtained from the dataset.
Tab. 16 shows the performance values attained from the algorithms applied to the sixth dataset. The sixth experimental dataset consisted of 2000 Twitter data items, with 661 labelled as negative and 1339 as positive. Because a total of 51 features were extracted from the sixth dataset, the dimension parameter of SSA was set to 51. In total, 1482 document vectors were created. The order of performance of the algorithms used for the sixth experimental dataset is presented in Tab 17.
In the sixth set of experiments, SVM was the best in terms of accuracy, precision, and sensitivity, whilst the best selectivity value was obtained from kNN. The model generated by SSA for the six experimental datasets showed the best accuracy value in the first and fifth experiment sets, and the best precision values in the first and third experiment sets. SSA achieved the best sensitivity value in the fourth set of experiments, and the best selectivity value in the fifth set of experiments. It is therefore predicted that the performance of SSA in SA may increase if the initial parameters of the SSA are accurately set, that feature selection is performed, cross-validation is performed, or the number of models for the classes is increased. Different similarity metrics may also affect the results. Performance rankings of all experiment sets are summarized in Fig. 2.

CONCLUSIONS
SA is a computational study for the contextual mining of text to determine the opinions, appraisals, attitudes, and sentiment of speakers or writers toward topics, events, issues, individuals, attributes, and their entities based on the language they use. It can be considered as the basis of different social network analysis problems.
When the studies in the literature were examined, it was observed that the studies mostly suggested ML and deep learning techniques/models to solve social network problems. In this study, unlike the others, as far as we know, a metaheuristic algorithm was proposed for SA for the first time. SSA achieved higher performance metrics than other ML algorithms in most of the six experiments performed. SSA among all experiments recorded the highest success with the highest sensitivity value of 82,6%. One of the biggest reasons why metaheuristic SSA was preferred in this study was its high convergence speed.
In the current study, a novel approach was proposed for the SA within pre-labelled Twitter data. A novel classification model was created for the SA and opinion mining studies by adapting SSA. The proposed SSA model and ML techniques were compared and it can be concluded that metaheuristic algorithms can be utilized as an alternative to supervised or unsupervised ML techniques for social networks with promising results. To the best of our knowledge, no artificial intelligence optimization algorithm has previously been studied for SA. This study may be considered important because it shows that social networks can also be analysed in terms of optimization. This study also introduced a new application domain for the intelligent optimization algorithms, especially for SSA.
In order to increase the success of the results obtained, different similarity measures could be used. Also, more than one model could be created for each sentiment class instead of a single solution/model. It is thought that the performance could also be increased by integrating the feature selection. In addition, the classifier ensemble method could be integrated into the adapted SSA to increase the sentiment classification performance. Furthermore, the problem could be modelled as a multiobjective problem. It is anticipated that with this alternative approach, more successful results could be achieved.
In future studies, the proposed method is aimed to be adapted as a solution search algorithm for different social network analysis problems. In order to increase the success of this optimization method in terms of different metrics, different algorithms may be combined and hybridized approaches may be proposed with parallel or distributed versions.