# An Evolutionary Computation Approach for Twitter Bot Detection
## 4 Proposed Approach
### Genetic Algorithm  
For the GA used in this paper, an individual is a real vector \(\tilde{\mathbf{w}}\in\mathbb{R}^{d}\) where \(d\in\mathbb{N}\). In particular, each individual represents the weights of a neural network with no hidden layers, a single output perceptron, and a bias fixed to be 0. The hypothesis function has the following form:  
\[h_{GA}^{\mathbf{w}}(\mathbf{x})=\mathtt{int}(\mathbf{w}\cdot\mathbf{x}\leq 0) \tag{8}\]  
where \(\mathbf{w}\in\mathbb{R}^{d}\) is the best individual in the GA process. We use the GA process to discover a real vector of weights for the input features so that the components of \(\mathbf{w}\) that are very close to 0 are those related to the features that the GA does not consider relevant for prediction. On the other hand, components (weights) of \(\mathbf{w}\) that are large in absolute value are related to features that have significant importance when it comes to classifying a given user account \(u\) either as bot or human. The hypothesis function performs a linear combination of the input features weighted according to \(\mathbf{w}\), then performs the classification by inspecting the sign of the resulting value. A classification model defined in this way may be able to compute interpretable predictions mainly for two reasons. On the one hand, it is possible to discover features that are not meaningful for the prediction by inspecting the components of \(\mathbf{w}\) that are approximately equal to 0. On the other hand, it is possible to discover how much a feature \(j\) is important for the prediction by inspecting the absolute value of the corresponding weight, namely, the \(j\)th component of \(\mathbf{w}\). Furthermore, by inspecting the sign of this component, it is possible to discover which of the two categories is more likely to be predicted by the feature \(j\). In our case, a positive sign for the \(j\)th component of \(\mathbf{w}\) means that the feature \(j\) potentially predicts a human, while a negative sign means that the feature \(j\) potentially predicts a bot. In this setting, we can take advantage of GA to learn the real vector \(\mathbf{w}\) to maximize a given quality objective related to our detection problem. Specifically, our problem is a single-objective optimization problem in which we want to minimize the following fitness function, that is, the mean squared error. \[\text{MSE}_{GA}(\tilde{\mathbf{w}},\tilde{X},\tilde{y})=\frac{\sum_{i=1}^{| \tilde{X}|}(h_{GA}^{\mathbf{w}}(\tilde{X}^{i})-\tilde{y}_{i})^{2}}{|\tilde{X}|} \tag{9}\]  
We are interested in finding a real vector of weights such that:  
\[\mathbf{w}=\arg\min_{\tilde{\mathbf{w}}\in\mathbb{R}^{d}}\text{MSE}_{GA}( \tilde{\mathbf{w}},\tilde{X},\tilde{y}) \tag{10}\]  
where \(\tilde{X}\in\mathbb{R}^{s\times d}\) is a sample obtained by randomly extracting, without replacement, \(s\in\mathbb{N}\) with \(s\leq n\) observations from training set \(X\), while \(\tilde{y}\in\{0,1\}^{s}\) are the corresponding ground-truth labels. In particular, we repeat this random sampling every generation during the evolutionary process with  
\[s\simeq\lfloor 0.6n\rfloor\]  
Each generation corresponds to a different random sample from the training set. Moreover, this random sample is balanced in terms of class distribution. In this way, we avoid extracting a sample where a class is overrepresented, and thus we avoid biasing the evolutionary process towards models that are likely to predict the majority class. Since random sampling is repeated at the beginning of each generation, overfitting should be avoided at the end of the evolutionary process.