# Friend Recommender System for Social Networks Based on Stacking Technique and Evolutionary Algorithm

Authors: Aida Ghorbani; Amir Daneshvar; Ladan Riazi; Reza Radfar
Journal: Complexity
 (2022)

---

## Abstract

In recent years, social networks have made significant progress and the number of people who use them to communicate is increasing day by day. The vast amount of information available on social networks has led to the importance of using friend recommender systems to discover knowledge about future communications. It is challenging to choose the best machine learning approach to address the recommender system issue since there are several strategies with various benefits and drawbacks. In light of this, a solution based on the stacking approach was put out in this study to provide a buddy recommendation system in social networks. Additionally, a decrease in system performance was caused by the large amount of information that was accessible and the inefficiency of some functions. To solve this problem, a particle swarm optimization (PSO) algorithm to select the most efficient features was used in our proposed method. To learn the model in the objective function of the particle swarm algorithm, a hybrid system based on stacking is proposed. In this method, two random forests and Extreme Gradient Boosting (XGBoost) had been used as the base classifiers. The results obtained from these base classifiers were used in the logistic regression algorithm, which has been applied sequentially. The suggested approach was able to effectively address this issue by combining the advantages of the applied strategies. The results of implementation and evaluation of the proposed system show the appropriate efficiency of this method compared with other studied techniques.


---

## Body

## 1. Introduction

In recent years, by the development of social networks, individuals and organizations can easily interact with each other. People can get their favorite connections in different fields and share their knowledge as well. Most of the connections that individuals are making on social networks exist only in the virtual world and are not often accessible there. A social network is a graph in which each node stands for a person, group, or organization, and each link between nodes depicts the relationships among them. Understanding and describing the processes that create social interactions is one of the fundamental problems in social network analysis. In this regard, the problem of link prediction in social networks states that two nodes in a network will be connected in the near future or not[1].One of the most important issues in social networks, which leads to its superiority over other networks, is the friend recommender system in it. In recent years, many methods were proposed to suggest a friend recommender system that had been used machine learning techniques and artificial intelligence [2, 3]. The performance of its methods is not, however, clearly categorized in the area of machine learning. This is mostly because there are so many methods and suggested adjustments in the literature. As a result, choosing a proper machine learning algorithm is difficult and confusing that fits the needs of the issue when developing a recommender system. Thus, considering that each machine learning method has its advantages and limitations, an approach based on stacking technique is presented that can combine the advantages of machine learning methods and improve the results.Before moving on to the next phase of this study, a review of earlier techniques is provided. The different parts of the research’s suggested system are then discussed. The outcomes of the system’s implementation are then examined using a number of tests, and conclusions are provided at the end.


## 2. Related Work

The problem of link prediction, which first raised by Getoor and Diehl, is presented as a problem of predicting the presence of a link between two entities. The prediction is based on the properties of other objects and other observed links [4]. This is widely used in a wide range of real and important areas, especially those involving the detection of complex events from highly structured data [5]. A thorough summary of link prediction in various networks was given in a research by Daud et al. The report gave thorough descriptions of link prediction algorithms, cutting-edge technology, programs, problems, and future research objectives. Besides, several directions for future research in the field of link prediction in social networks were expressed [6].In a research by Chen et al. [7], the encoder-LSTM-decoder (E-LSTM-D) system is proposed as a new deep learning model based on stacked long short-term memory (LSTM) in the encoder-decoder architecture. The various experiments performed in this paper show that the E-LSTM-D model in different datasets performs significantly better than the existing dynamic link prediction methods. Behera et al. used potential future linkages using a variety of machine learning algorithms, including K-NN, MLP, bagging, SVM, and decision trees, based on attributes retrieved from the topological structure. The performance of the proposed system of this research was evaluated in terms of various criteria [8].In a research by Chonghuan [9], to solve the problem of sparsity of recommender systems, a new recommendation method for social network using matrix factorization technique proposed. In this method, users clustered and various complex factors considered as well. The simulation results showed that the proposed socialized recommendation method based on matrix factorization (SRM-MF) system performed better than the methods available on the tested dataset. For instance, the precision of the real dataset and the Book-Crossing dataset are 0.088 and 0.095, respectively, assuming the Hamming distance is 20. While 0.073 and 0.086, respectively, represent the greatest accuracy for other procedures used in similar circumstances, Pecli et al.’s experiments were performed on three datasets (Microsoft Academic Network, Amazon, and Flickr) that included more than twenty different features, including topological features and domain-specific features. The program combines three feature selection strategies, six different classification algorithms (support vector machines (SVM), k-nearest neighbors (K-NN), simple Bayesian, Classification and Regression Tree (CART), random forest, and multilayer perceptron) and three evaluation criteria (precision, F-measure, and area under the curve). Their research’s findings revealed an intriguing relationship between the majority of the chosen characteristics and the dataset. The findings demonstrated that using feature selection techniques to condense the feature set produces better classification models than classifiers built using the whole set of features [10]. In the paper by Manshad et al., a new time series link prediction (TSLP) method based on irregular cellular learning automaton (ICLA) and evolutionary computation (EC) proposed. ICLA-EC had been used to analyze network evolution through neighborhood dynamicity. Based on experiments performed on different datasets, ICLA-EC-TSLP achieved significant results (0.7212–0.8650) in AUC criterion compared with other methods [11].In Cai et al.’s research, a new link prediction model based on line graph neural networks is proposed that achieves good performance for the link prediction problem. Studies on 14 datasets revealed that the suggested approach of this study consistently outperformed all fundamental techniques in terms of area under the curve (AUC) by identifying more relevant features [12]. In the research of Parveen et al., the friends’ recommendation system performed using different types of machine learning algorithms, such as Random Forest Classifier, XGBoost, Light GBM, and Cat Boost. The performance of the mentioned methods compared in F1-score criteria, accuracy, recall, and confusion matrix. The results of this study showed that Random Forest and Light GBM are less accurate than the XGBoost and CatBoost algorithms. The accuracy of the XGBoost and CatBoost algorithms was the same and equal to 95% [13].Kumar et al. proposed a friend recommendation system that uses a random forest to advise a buddy. The data collection used in this study has 94,000 nodes. The achieved accuracy for this suggested model is 89%. It is stated that the accuracy obtained in relation to the available hardware and data volume is quite reasonable [14]. In the research of Murali et al., a recommendation system presented in which each user is offered the best research articles in this field. This recommendation method is based on the individual queries and similarities found from other users based on their queries. This recommendation system uses a collaborative filtering approach and helps to avoid user time-consuming [15].In the research done by ZhengWei et al. [16], a solution based on XGBoost is proposed for classifying and recommending journals to researchers. The doc2vec is used to get better results. The accuracy of this method was measured at 84.24 percent after testing on Common SCI English publications in the computing industry to verify the findings. A unique Graph Neural Network for Reciprocal Recommendation (GraphRR) was suggested for exploiting multiplex user interactions in the research written by Chang et al. [17]. To display each user’s preference, attraction, and likeness, three ego graphs are created for each user depending on the directions of interaction. Then, multiplexity-aware GNN modules are applied to measure participation. Extensive tests were conducted on large-scale real-world online gaming datasets from NetEase Games, which demonstrated the system’s good performance.As it is clear from the reviewed researches, recommender systems used in different fields and have of special importance. Studies shown that using machine learning techniques in this field is high and could be developed due to the nature of artificial intelligence methods. In Table1, a summary of the reviewed related works is given.Table 1
Summary of related works.
ResearchFieldMethodDataset[7]Link predictionEncoder-LSTM-decoder (E-LSTM-D) systemCONTACT, ENRON, RADOSLAW, FB-FORUM, LKML[8]Link predictionK-NN, MLP, bagging, SVM, and decision treeCollected dataset[9]Recommendation system in social networkSRM-MFActual dataset, Book-Crossing[10]Link prediction applicationsSelected feature method with SVM, K-NN, simple Bayesian, CART, random forest, and multilayer perceptronMicrosoft Academic Network, Amazon, and Flickr[11]Link predictionICLA-EC-TSLPHep-th, Hep-ph, Astro-ph, Email-Enron, CollegeMsg[12]Link predictionLine graph neural networks14 various datasets[13]Friend recommendation systemRandom Forest Classifier, XGBoost, Light GBM, and Cat BoostFacebook dataset[14]Friend recommendation systemRandom forestFacebook recruiting[15]Research recommendation systemCollaborative filteringCollected datasetZhengWei et al. [16]Classification and recommendation of academic journalsXGBoost with doc2vecCommon SCI English journalsChang et al. [17]Reciprocal recommendationGraphRRReal-world large-scale online games from NetEase Games


## 3. Proposed System

This paper aims to propose a new way as an effective approach based on the use of particle swarm optimization and ensemble methods for friend recommendation in social network. Details of the proposed system are shown in Figure1.Figure 1
Proposed system.The proposed system of this research uses particle swarm optimization algorithm to select effective features. Each particle in this method represents a set of characteristics that iteratively progress toward the best answer. In this algorithm, a particle that chooses the optimal attributes for the issue is ultimately chosen. The method used to learn the objective function of the particle swarm optimization algorithm involves a stacked model of several machine learning algorithms.There are several ways to learn the model, and usually each of them has power in a particular area, and to use one of them, the necessary studies must be done to understand how they work. There is no algorithm that is always the best, and each approach performs differently depending on the data and the situation. This is a key concept in these algorithms and models. In these situations, combining the output of many classifiers is preferable than selecting a specific approach or technique. Since each of them may have different strengths and weaknesses, it is expected that their participation would have a good compensatory effect.One of the best and most effective combining methods is the use of stacking technique in which multiple models are combined. This method is used to increase the accuracy of models and improve results and reliability in a wide range of business and research programs. Stacking is a learning-based method, which combines multiple classification models or regression models. There are two stages to the categorization process based on this model. The output of the first level of classifiers serves as the input for the classifiers at the second level in the stacking approach. In other words, it can be said that classifier prediction at one level is considered as a feature for the next level classifier.In this regard, in the proposed method of this research, XGBoost methods and two forms of random forest are implemented for the first level. The results of the first-level algorithms are used in logistic regression, which is implemented in the second level of the proposed system. Finally, the obtained results are used as the fitness result in the objective function of the particle swarm optimization algorithm.


### 3.1. Data Preparation

The link prediction collection has been used. This collection could be find at Noesis, nd. This collection of information has collected 22 networks from different sources and fields. This dataset includes a wide range of different features and information. A summary of the information in these datasets is given in Table2. Name of the network, number of nodes, number of edges, average degree, average clustering coefficient, and average length of shortest route, dimension, heterogeneity, and assortativity are all listed in the table from left to right [21]. BUP dataset and a few additional datasets were used to test the proposed system. The BUP dataset represents the network information of political blogs. This dataset includes 105 nodes, 441 links, and 8.4 degrees (Table 2).Table 2
Topological properties of networks [21].
NameVEkCASPLDHrUPG494165942.670.0818.99461.45040.0035HPD8756323317.380.114.19144.5133−0.051ERD6927118503.420.123.78412.6708−0.1156YST228466465.820.134.29112.8479−0.0991EML113354519.620.223.6181.94210.0782ADV51553928515.240.253.2295.4060−0.0951KHN3772127186.740.253.63129.422−0.1205PGP10680243164.550.277.49244.14650.2382CEG297214814.460.292.4651.8008−0.1632LDG8324415329.980.314.37166.188−0.0997SMG102449169.60.312.9863.9475−0.1925ZWL66515418216.290.323.85102.58510.0006INF410276513.490.463.6391.38760.2258BUP1054418.40.493.0871.4207−0.1279HTC7610157514.140.495.68192.09860.2939CGS6158118983.860.493.62143.94670.2426GRQ5241144845.530.535.05173.05230.6593EMT24261663013.710.543.15103.10110.0474FBK40248788743.680.593.98132.4320.0707UAL332212612.810.632.7463.4639−0.2079CDM16264475945.850.645.82182.20870.1846NSC146127423.750.692.59171.84860.4616


#### 3.1.1. Normalization

Normalization is an operation on raw data that rescale the data or transform the data so that each attribute has a uniform contribution. Doing this will solve the problem of dominant features and outliers. Based on statistical criteria, there are many techniques for normalizing data within a certain range. The Z-score normalizing approach is used in this case for normalization. In this method, the criteria of mean and standard deviation are used to rescale the data so that the resulting features have a zero mean and a unit variance.Each instance,xi,n, of the data is transformed into x′i,n as follows:(1)Xi,n'=Xi,n−μiσi,where μ and σ denote the mean and standard deviation of ith feature, respectively [22].


#### 3.1.2. Feature Engineering

Nod2vec and NetworkX packages are used for feature engineering in this research. One of the introduced solutions for selecting features from a graph is known as Node2Vec. Node2vec is a flexible neighborhood sampling strategy that allows us to gently interpolate between BFS (Breadth First Search) and DFS (Depth First Search). This method is implemented by developing a biased flexible random walking method that can explore neighbors in both BFS and DFS methods [20].A random walk is defined by two parametersp and q. We assume that the current random walking position is node v. The position of the previous step is node t. In order to determine the next position, the probabilities of πvx transfer at the edges (v, x) leading to v must be evaluated. We set the probability of anomalous transfer to πvx = αpq (t, x)·wvx. In particular, αpq is defined as follows:(2)αpq=1p,dtx=0,1,dtx=1,1q,dtx=2,where dtx defines the shortest distance between node t and node x, and the value of dtx must be 0, 1, or 2. The p parameter controls the possibility of revisiting a node during a random walk. When the p value is high, the visited nodes are rarely sampled. This strategy promotes moderate exploration and eliminates redundant sampling across two hops. Alternatively, if p is small, the walk is directed backward by one step (Figure 2), keeping it “local” and near to the initial node u.Figure 2
Node selection in Node2Vec algorithm. The current position in a random walk is at node v, and the previous step is at node (t). In this example, x1, x2, and x3 are neighbors. The values of apq are calculated based on the distance between v and t. [21].Theq parameter allows the search to distinguish between “local” and “global” nodes. As shown in Figure 2, if q > 1, a random walk is more likely to be sampled from nodes around the node. BFS samples the nodes in a small location. Conversely, if q < 1, the random walk is farther away from v, which can receive more general information about the features. Therefore, the distance between the sampling node and the given source node does not increase strictly [21].Recently, huge amounts of network data in various fields such as web pages, social networks, and power grids are being generated and collected. NetworkX package was created in April 2005 to analyze these massive and complex networks in Python [22]. This Python package is intended for building, modifying, and researching the composition and operation of complicated networks. A variety of networks or diagrams are shown using its data structures. In contrast to many other technologies, NetworkX is extremely versatile and built to handle data at a scale appropriate for contemporary issues. In this package, nodes can represent any object in Python, and edges can contain arbitrary data. In Figure 3, a graph plot of BUP data that created by NetworkX is shown. This figure shows the nodes and how they (edges) are connected.Figure 3
A graph plot of BUP data that created by NetworkX.


#### 3.1.3. Data Splitting

To implement and evaluate the efficiency of the proposed system, the data studied in this research are divided into two segments: training data and test data. In this classification, 70% of the total data examined is used for system training. To evaluate the system, the remaining 30% is considered as test data.


### 3.2. Classification Model

In these methods, classifiers had been combined to produce better predictions compared with single-level models. To do this, the stacking technique is used to implement several consecutive classifiers. As mentioned in the proposed system, several XGBoost is execution technique to increase the accuracy and performance of the Gradient Boosting Machine (GBM) and especially to increase the classification accuracy of regression trees proposed in [23], and two random forest algorithms have been ran in the first level, and finally, logistic regression model is one of the statistical tools used for data analysis, in which the relationship between a dependent variable and independent variables defined based on a series of observational values [24] and in the second level combined with them sequentially. The results of the first-level classifiers combined as the input of the second level and the final prediction in the second level are based on the results obtained from the first level.Because of the regular and parallel processing, XGBoost outperforms GBM. This approach integrates all predictors simultaneously for enhanced training [25]. The XGBoost algorithm is a system that successively generates decision trees. This algorithm can perform calculations relatively faster than all computing environments. XGBoost is widely used in modeling and classification for its performance.Many decision trees grow in the classification of random forest algorithms, which is a batch algorithm. A decision tree algorithm can easily perform classification operations on events. The random forest algorithm uses several decision trees. In fact, a set of decision trees together produce a forest, and this forest can make better decisions (than a tree). In general, the decision tree is prone to overtraining and has little generalizability. The volatility of the decision tree’s findings in the presence of noise in the input data is another drawback. A slight shift in learning patterns during the construction of a decision tree may result in significant changes to the tree’s structure. Random forest, which operates by averaging the outcomes of all decision trees, is used to tackle these issues. The most important feature of stochastic forests is their high performance to measure the importance of variables, thus determining the role of each variable in predicting the response [26].


### 3.3. Feature Selection

In solving many problems, machine learning methods have difficulty in dealing with a large number of input features. One of the most crucial strategies in data preparation and feature selection is crucial for the efficient and accurate use of machine learning technologies. One of the important steps in the machine learning process is feature selection. This process identifies relevant features and removes irrelevant and additional data [27]. This process speeds up data mining algorithms, improves prediction accuracy, and increases comprehensibility. Irrelevant features are those that do not provide any useful information, and additional features do not provide more information than currently selected features.In the proposed method of this research, particle swarm optimization algorithm is used to select the features. In this section, more relevant features are selected so that the performance of the friend recommender system is improved. The particle swarm optimization algorithm is a social search algorithm based on the social behavior and regular collective movements of birds and fish [28]. Despite the limited ability of each particle to find the best pattern, their collective behavior has a great ability to find the best path (in other words the best answer to optimization problems) as the position of each particle changes based on the particle’s experience in previous movements and neighboring particle experiences. In fact, each particle is aware of its superiority or lack of superiority over neighboring particles as well as the whole group.Two perspectives were considered to model the order in the collective movement of these particles. One dimension is the social interactions between group members, and the other dimension is the individual superiority that each group member may have. In the first dimension, all members of the group are obliged to always change their position by following the best person in the group. In the second dimension, it is necessary for each member to keep in their memory the best situation they have personally experienced and to have a tendency toward the best perceived situation of their past. Each of these members may become the leader of the group so that the other members have the duty to follow them.After generating the initial population (particles) and considering an initial velocity for each particle, the fitness of each particle is calculated based on its position. Each particle in the search space represents one solution for the problem and changes its speed based on the best answer obtained in the particle group (best person in the group) and the best place that it has ever been. This velocity is added to the position of the particle, and a new position of the particle is obtained. In subsequent iterations, the best particle in terms of fitness helps the other particles and corrects their motion, and after successive iterations, the problem will converge towards the optimal answer.The position vector for the ith particle with dimensiond is Xi=xi,1,xi,2,…,xi,d. The velocity vector is defined as Vi=vi,1,vi,2,…,vi,d.During motion, the best position that each particle can reach during the execution of the algorithm is called pbest =pb,1,pb,2,…,pb,d, and the best position that all particles have gained during the execution of the algorithm is called gbest =  gb,1,gb,2,…,gb,d. The position and velocity vectors of each particle are defined as follows:(3)vi,dt+1=wt⋅vi,dt+c1⋅rand1pbesti,dt−xi,dt+c2,xi,dt+1=xi,dt+vi,dt+1.c1 is learning coefficient related to personal experiences of each particle and c2 is learning coefficient related to group experiences. The rand1 is random number between [0 1]. The wt is a control parameter that controls the effect of the current particle velocity on the next velocity and creates a balance between the algorithm’s ability to search locally and globally.


## 3.1. Data Preparation

The link prediction collection has been used. This collection could be find at Noesis, nd. This collection of information has collected 22 networks from different sources and fields. This dataset includes a wide range of different features and information. A summary of the information in these datasets is given in Table2. Name of the network, number of nodes, number of edges, average degree, average clustering coefficient, and average length of shortest route, dimension, heterogeneity, and assortativity are all listed in the table from left to right [21]. BUP dataset and a few additional datasets were used to test the proposed system. The BUP dataset represents the network information of political blogs. This dataset includes 105 nodes, 441 links, and 8.4 degrees (Table 2).Table 2
Topological properties of networks [21].
NameVEkCASPLDHrUPG494165942.670.0818.99461.45040.0035HPD8756323317.380.114.19144.5133−0.051ERD6927118503.420.123.78412.6708−0.1156YST228466465.820.134.29112.8479−0.0991EML113354519.620.223.6181.94210.0782ADV51553928515.240.253.2295.4060−0.0951KHN3772127186.740.253.63129.422−0.1205PGP10680243164.550.277.49244.14650.2382CEG297214814.460.292.4651.8008−0.1632LDG8324415329.980.314.37166.188−0.0997SMG102449169.60.312.9863.9475−0.1925ZWL66515418216.290.323.85102.58510.0006INF410276513.490.463.6391.38760.2258BUP1054418.40.493.0871.4207−0.1279HTC7610157514.140.495.68192.09860.2939CGS6158118983.860.493.62143.94670.2426GRQ5241144845.530.535.05173.05230.6593EMT24261663013.710.543.15103.10110.0474FBK40248788743.680.593.98132.4320.0707UAL332212612.810.632.7463.4639−0.2079CDM16264475945.850.645.82182.20870.1846NSC146127423.750.692.59171.84860.4616


### 3.1.1. Normalization

Normalization is an operation on raw data that rescale the data or transform the data so that each attribute has a uniform contribution. Doing this will solve the problem of dominant features and outliers. Based on statistical criteria, there are many techniques for normalizing data within a certain range. The Z-score normalizing approach is used in this case for normalization. In this method, the criteria of mean and standard deviation are used to rescale the data so that the resulting features have a zero mean and a unit variance.Each instance,xi,n, of the data is transformed into x′i,n as follows:(1)Xi,n'=Xi,n−μiσi,where μ and σ denote the mean and standard deviation of ith feature, respectively [22].


### 3.1.2. Feature Engineering

Nod2vec and NetworkX packages are used for feature engineering in this research. One of the introduced solutions for selecting features from a graph is known as Node2Vec. Node2vec is a flexible neighborhood sampling strategy that allows us to gently interpolate between BFS (Breadth First Search) and DFS (Depth First Search). This method is implemented by developing a biased flexible random walking method that can explore neighbors in both BFS and DFS methods [20].A random walk is defined by two parametersp and q. We assume that the current random walking position is node v. The position of the previous step is node t. In order to determine the next position, the probabilities of πvx transfer at the edges (v, x) leading to v must be evaluated. We set the probability of anomalous transfer to πvx = αpq (t, x)·wvx. In particular, αpq is defined as follows:(2)αpq=1p,dtx=0,1,dtx=1,1q,dtx=2,where dtx defines the shortest distance between node t and node x, and the value of dtx must be 0, 1, or 2. The p parameter controls the possibility of revisiting a node during a random walk. When the p value is high, the visited nodes are rarely sampled. This strategy promotes moderate exploration and eliminates redundant sampling across two hops. Alternatively, if p is small, the walk is directed backward by one step (Figure 2), keeping it “local” and near to the initial node u.Figure 2
Node selection in Node2Vec algorithm. The current position in a random walk is at node v, and the previous step is at node (t). In this example, x1, x2, and x3 are neighbors. The values of apq are calculated based on the distance between v and t. [21].Theq parameter allows the search to distinguish between “local” and “global” nodes. As shown in Figure 2, if q > 1, a random walk is more likely to be sampled from nodes around the node. BFS samples the nodes in a small location. Conversely, if q < 1, the random walk is farther away from v, which can receive more general information about the features. Therefore, the distance between the sampling node and the given source node does not increase strictly [21].Recently, huge amounts of network data in various fields such as web pages, social networks, and power grids are being generated and collected. NetworkX package was created in April 2005 to analyze these massive and complex networks in Python [22]. This Python package is intended for building, modifying, and researching the composition and operation of complicated networks. A variety of networks or diagrams are shown using its data structures. In contrast to many other technologies, NetworkX is extremely versatile and built to handle data at a scale appropriate for contemporary issues. In this package, nodes can represent any object in Python, and edges can contain arbitrary data. In Figure 3, a graph plot of BUP data that created by NetworkX is shown. This figure shows the nodes and how they (edges) are connected.Figure 3
A graph plot of BUP data that created by NetworkX.


### 3.1.3. Data Splitting

To implement and evaluate the efficiency of the proposed system, the data studied in this research are divided into two segments: training data and test data. In this classification, 70% of the total data examined is used for system training. To evaluate the system, the remaining 30% is considered as test data.


## 3.1.1. Normalization

Normalization is an operation on raw data that rescale the data or transform the data so that each attribute has a uniform contribution. Doing this will solve the problem of dominant features and outliers. Based on statistical criteria, there are many techniques for normalizing data within a certain range. The Z-score normalizing approach is used in this case for normalization. In this method, the criteria of mean and standard deviation are used to rescale the data so that the resulting features have a zero mean and a unit variance.Each instance,xi,n, of the data is transformed into x′i,n as follows:(1)Xi,n'=Xi,n−μiσi,where μ and σ denote the mean and standard deviation of ith feature, respectively [22].


## 3.1.2. Feature Engineering

Nod2vec and NetworkX packages are used for feature engineering in this research. One of the introduced solutions for selecting features from a graph is known as Node2Vec. Node2vec is a flexible neighborhood sampling strategy that allows us to gently interpolate between BFS (Breadth First Search) and DFS (Depth First Search). This method is implemented by developing a biased flexible random walking method that can explore neighbors in both BFS and DFS methods [20].A random walk is defined by two parametersp and q. We assume that the current random walking position is node v. The position of the previous step is node t. In order to determine the next position, the probabilities of πvx transfer at the edges (v, x) leading to v must be evaluated. We set the probability of anomalous transfer to πvx = αpq (t, x)·wvx. In particular, αpq is defined as follows:(2)αpq=1p,dtx=0,1,dtx=1,1q,dtx=2,where dtx defines the shortest distance between node t and node x, and the value of dtx must be 0, 1, or 2. The p parameter controls the possibility of revisiting a node during a random walk. When the p value is high, the visited nodes are rarely sampled. This strategy promotes moderate exploration and eliminates redundant sampling across two hops. Alternatively, if p is small, the walk is directed backward by one step (Figure 2), keeping it “local” and near to the initial node u.Figure 2
Node selection in Node2Vec algorithm. The current position in a random walk is at node v, and the previous step is at node (t). In this example, x1, x2, and x3 are neighbors. The values of apq are calculated based on the distance between v and t. [21].Theq parameter allows the search to distinguish between “local” and “global” nodes. As shown in Figure 2, if q > 1, a random walk is more likely to be sampled from nodes around the node. BFS samples the nodes in a small location. Conversely, if q < 1, the random walk is farther away from v, which can receive more general information about the features. Therefore, the distance between the sampling node and the given source node does not increase strictly [21].Recently, huge amounts of network data in various fields such as web pages, social networks, and power grids are being generated and collected. NetworkX package was created in April 2005 to analyze these massive and complex networks in Python [22]. This Python package is intended for building, modifying, and researching the composition and operation of complicated networks. A variety of networks or diagrams are shown using its data structures. In contrast to many other technologies, NetworkX is extremely versatile and built to handle data at a scale appropriate for contemporary issues. In this package, nodes can represent any object in Python, and edges can contain arbitrary data. In Figure 3, a graph plot of BUP data that created by NetworkX is shown. This figure shows the nodes and how they (edges) are connected.Figure 3
A graph plot of BUP data that created by NetworkX.


## 3.1.3. Data Splitting

To implement and evaluate the efficiency of the proposed system, the data studied in this research are divided into two segments: training data and test data. In this classification, 70% of the total data examined is used for system training. To evaluate the system, the remaining 30% is considered as test data.


## 3.2. Classification Model

In these methods, classifiers had been combined to produce better predictions compared with single-level models. To do this, the stacking technique is used to implement several consecutive classifiers. As mentioned in the proposed system, several XGBoost is execution technique to increase the accuracy and performance of the Gradient Boosting Machine (GBM) and especially to increase the classification accuracy of regression trees proposed in [23], and two random forest algorithms have been ran in the first level, and finally, logistic regression model is one of the statistical tools used for data analysis, in which the relationship between a dependent variable and independent variables defined based on a series of observational values [24] and in the second level combined with them sequentially. The results of the first-level classifiers combined as the input of the second level and the final prediction in the second level are based on the results obtained from the first level.Because of the regular and parallel processing, XGBoost outperforms GBM. This approach integrates all predictors simultaneously for enhanced training [25]. The XGBoost algorithm is a system that successively generates decision trees. This algorithm can perform calculations relatively faster than all computing environments. XGBoost is widely used in modeling and classification for its performance.Many decision trees grow in the classification of random forest algorithms, which is a batch algorithm. A decision tree algorithm can easily perform classification operations on events. The random forest algorithm uses several decision trees. In fact, a set of decision trees together produce a forest, and this forest can make better decisions (than a tree). In general, the decision tree is prone to overtraining and has little generalizability. The volatility of the decision tree’s findings in the presence of noise in the input data is another drawback. A slight shift in learning patterns during the construction of a decision tree may result in significant changes to the tree’s structure. Random forest, which operates by averaging the outcomes of all decision trees, is used to tackle these issues. The most important feature of stochastic forests is their high performance to measure the importance of variables, thus determining the role of each variable in predicting the response [26].


## 3.3. Feature Selection

In solving many problems, machine learning methods have difficulty in dealing with a large number of input features. One of the most crucial strategies in data preparation and feature selection is crucial for the efficient and accurate use of machine learning technologies. One of the important steps in the machine learning process is feature selection. This process identifies relevant features and removes irrelevant and additional data [27]. This process speeds up data mining algorithms, improves prediction accuracy, and increases comprehensibility. Irrelevant features are those that do not provide any useful information, and additional features do not provide more information than currently selected features.In the proposed method of this research, particle swarm optimization algorithm is used to select the features. In this section, more relevant features are selected so that the performance of the friend recommender system is improved. The particle swarm optimization algorithm is a social search algorithm based on the social behavior and regular collective movements of birds and fish [28]. Despite the limited ability of each particle to find the best pattern, their collective behavior has a great ability to find the best path (in other words the best answer to optimization problems) as the position of each particle changes based on the particle’s experience in previous movements and neighboring particle experiences. In fact, each particle is aware of its superiority or lack of superiority over neighboring particles as well as the whole group.Two perspectives were considered to model the order in the collective movement of these particles. One dimension is the social interactions between group members, and the other dimension is the individual superiority that each group member may have. In the first dimension, all members of the group are obliged to always change their position by following the best person in the group. In the second dimension, it is necessary for each member to keep in their memory the best situation they have personally experienced and to have a tendency toward the best perceived situation of their past. Each of these members may become the leader of the group so that the other members have the duty to follow them.After generating the initial population (particles) and considering an initial velocity for each particle, the fitness of each particle is calculated based on its position. Each particle in the search space represents one solution for the problem and changes its speed based on the best answer obtained in the particle group (best person in the group) and the best place that it has ever been. This velocity is added to the position of the particle, and a new position of the particle is obtained. In subsequent iterations, the best particle in terms of fitness helps the other particles and corrects their motion, and after successive iterations, the problem will converge towards the optimal answer.The position vector for the ith particle with dimensiond is Xi=xi,1,xi,2,…,xi,d. The velocity vector is defined as Vi=vi,1,vi,2,…,vi,d.During motion, the best position that each particle can reach during the execution of the algorithm is called pbest =pb,1,pb,2,…,pb,d, and the best position that all particles have gained during the execution of the algorithm is called gbest =  gb,1,gb,2,…,gb,d. The position and velocity vectors of each particle are defined as follows:(3)vi,dt+1=wt⋅vi,dt+c1⋅rand1pbesti,dt−xi,dt+c2,xi,dt+1=xi,dt+vi,dt+1.c1 is learning coefficient related to personal experiences of each particle and c2 is learning coefficient related to group experiences. The rand1 is random number between [0 1]. The wt is a control parameter that controls the effect of the current particle velocity on the next velocity and creates a balance between the algorithm’s ability to search locally and globally.


## 4. Results

In this section, the results of the implementation of proposed system reviewed. To do this, the performance of the friend recommender system has been examined in 5 different modes. In these 5 modes, the XGBoost, first Random Forest, second Random Forest, Logistic Regression, and the proposed system were used as learning models. First, some of important parameters considered for different methods are stated in Table3.Table 3
Some of important parameters considered for different methods.
MethodParametersXGBoostNumber of boosting stages = 100loss function = “log_loss”Learning rate = 0.1Maximum depth of the individual regression estimators = 3RandomForest_1The number of trees in the forest = 20 measures the quality of a split = “gini”The number of features to consider when looking for the best split = “sqrt (n_features)”RandomForest_2The number of trees in the forest = 30 measures the quality of a split = “gini”The number of features to consider when looking for the best split = “sqrt (num of features)”Logistic regressionSolver = “lbfgs” penalty term = “L2”Tolerance for stopping criteria = 1e-4The results of this implementation are given in Table4. The values obtained for precision, recall, F-measure, and accuracy criteria for the mentioned methods for class one are given in this table. Based on the results of this table, the values of the criteria if the proposed system is used are 0.68, 0.70, 0.69, and 0.69, respectively. These findings demonstrate that if the suggested stacking strategy is used, the best results are achieved for every analyzed criterion. Better outcomes than individual base models are attained in the proposed system because basic learning models are stacked and their unique capabilities are used. The confusion matrix obtained from the stacking for the train and test data is given in Figure 4. Each column of the confusion matrix represents a sample of the predicted value, and each row contains actual sample. To classify two classes, each member sample will be either positive or negative. Therefore, for each data sample, four states may occur that are represented by the confusion matrix.Table 4
Result for class 1 in BUP dataset.
PrecisionRecallF-measureAccuracyXGBoost0.590.570.580.59RandomForest_1 (n_estimators = 20)0.670.630.650.66RandomForest_2 (n_estimators = 30)0.660.640.650.65Logistic regression0.580.590.590.58Proposed method0.680.700.690.69Figure 4
Confusion matrix for proposed method for BULP dataset. Left figure is for training, and right figure is for testing dataset.The sample is a member of a positive class and is recognized as a member of the same class (true positive). The sample is a member of the positive class and is recognized as a member of the negative class (false negative). The sample is a member of a negative class and is recognized as a member of the same class (true negative). Finally, the sample is a member of the negative class and is recognized as a positive class member (false positive).Since the elements on the main diameter show the correct samples (true positive and true negative), as shown in Figure4 for the training dataset, their sum is equal to the total number of samples. The values of the elements on the subdiameter show the incorrect samples (false negative and false positive), which are zero for the training dataset. Therefore, the confusion matrix for training data showed the highest possible performance.The confusion matrix findings for the test data show that there are not many false positive instances or false negative cases, which is acceptable. This demonstrates how well the suggested stacking approach works in both classes.


### 4.1. Results for Other Datasets

In this section, the proposed method on other datasets was also examined. These datasets are INF, CEG, and UAL, respectively. The results of applying different methods to INF dataset are listed in Table5.Table 5
Result for class 1 in INF dataset.
PrecisionRecallF-measureAccuracyXGBoost0.660.630.690.67RandomForest_1 (n_estimators = 20)0.710.670.690.70RandomForest_2 (n_estimators = 30)0.710.670.690.70Logistic regression0.530.530.530.53Proposed method0.730.680.700.71The results of applying different methods to CEG dataset are listed in Table6.Table 6
Result for class 1 in CEG dataset.
PrecisionRecallF-measureAccuracyXGBoost0.570.540.550.57RandomForest_1 (n_estimators = 20)0.650.610.630.64RandomForest_2 (n_estimators = 30)0.660.620.640.65Logistic regression0.530.540.540.53Proposed method0.630.660.640.64The results of applying different methods to UAL dataset are listed in Table7.Table 7
Result for class 1 in UAL dataset.
PrecisionRecallF-measureAccuracyXGBoost0.650.640.640.64RandomForest_1 (n_estimators = 20)0.680.680.680.68RandomForest_2 (n_estimators = 30)0.680.680.680.68Logistic regression0.630.590.610.62Proposed method0.750.750.750.75As can be observed, the suggested method performs rather well on the investigated datasets. The findings from the INF and UAL datasets demonstrated that the suggested system of this study outperformed the alternative algorithms in every analyzed criterion. In these two experiments, Random Forest_2 had the best performance after the proposed system. In testing the methods on CEG dataset, Random Forest_2 performed better in the precision and accuracy criteria, and the proposed system performed better in the recall and F-measure criteria. However, due to the fact that in the case of this study, overlooked cases (false negatives) are more costly than false alarms (false positive), and recall is more important than other criteria. Therefore, like the other two datasets, the proposed system of this research performs better on this dataset.


### 4.2. Research Limitations

Because a portion of the methodology utilized in this work is based on stacking several machine learning techniques, training the system takes a disproportionately long amount of time. The training procedure for huge graphs might take a long time if hardware resources were limited. For future work, according to the stated point, one can focus on reducing system training time. Applying intelligent sampling methods and using a subset of data for the training process can be considered.


## 4.1. Results for Other Datasets

In this section, the proposed method on other datasets was also examined. These datasets are INF, CEG, and UAL, respectively. The results of applying different methods to INF dataset are listed in Table5.Table 5
Result for class 1 in INF dataset.
PrecisionRecallF-measureAccuracyXGBoost0.660.630.690.67RandomForest_1 (n_estimators = 20)0.710.670.690.70RandomForest_2 (n_estimators = 30)0.710.670.690.70Logistic regression0.530.530.530.53Proposed method0.730.680.700.71The results of applying different methods to CEG dataset are listed in Table6.Table 6
Result for class 1 in CEG dataset.
PrecisionRecallF-measureAccuracyXGBoost0.570.540.550.57RandomForest_1 (n_estimators = 20)0.650.610.630.64RandomForest_2 (n_estimators = 30)0.660.620.640.65Logistic regression0.530.540.540.53Proposed method0.630.660.640.64The results of applying different methods to UAL dataset are listed in Table7.Table 7
Result for class 1 in UAL dataset.
PrecisionRecallF-measureAccuracyXGBoost0.650.640.640.64RandomForest_1 (n_estimators = 20)0.680.680.680.68RandomForest_2 (n_estimators = 30)0.680.680.680.68Logistic regression0.630.590.610.62Proposed method0.750.750.750.75As can be observed, the suggested method performs rather well on the investigated datasets. The findings from the INF and UAL datasets demonstrated that the suggested system of this study outperformed the alternative algorithms in every analyzed criterion. In these two experiments, Random Forest_2 had the best performance after the proposed system. In testing the methods on CEG dataset, Random Forest_2 performed better in the precision and accuracy criteria, and the proposed system performed better in the recall and F-measure criteria. However, due to the fact that in the case of this study, overlooked cases (false negatives) are more costly than false alarms (false positive), and recall is more important than other criteria. Therefore, like the other two datasets, the proposed system of this research performs better on this dataset.


## 4.2. Research Limitations

Because a portion of the methodology utilized in this work is based on stacking several machine learning techniques, training the system takes a disproportionately long amount of time. The training procedure for huge graphs might take a long time if hardware resources were limited. For future work, according to the stated point, one can focus on reducing system training time. Applying intelligent sampling methods and using a subset of data for the training process can be considered.


## 5. Conclusion

In this research, a friend recommender system based on a combination of XGBoost, random forest, and logistics regression techniques is proposed. The results of this approach’s implementation of XGBoost methods and two types of random forests were integrated using the stacking method and the logistics regression algorithm. The particle swarm optimization algorithm in this method chooses the most efficient characteristics to achieve the highest efficiency. For better investigation, in addition to the proposed stacking system, XGBoost-based system, linear regression, and random forest were implemented The results of this comparison showed that the proposed stacking system can achieve higher precision, recall, F-measure, and accuracy than other implemented approaches. This system has been able to make good diagnoses in both existing classes and achieve good results.


## 6. Introducing the Tool

Python programming language is used to implement the proposed solution. Python is a powerful programming language that is easy for people to learn. High-level data structures in this programming language are very efficient, and object-oriented programming is made possible. Python Interpreter and the extensive standard library are freely available on all major platforms on the Python website [29]. For the Python programming language, there are several libraries on machine learning and data mining issues. These features have led to the widespread use of this language in the field of artificial intelligence.



---

*Source: 5864545-2022-08-31.xml*