# Classification of Cyber-Aggression Cases Applying Machine Learning
## 3 Materials, Methods and Metrics
### Methods  
Random Forest. The Random Forest classification algorithm, developed by [PERSON] (1986), is a set of decision trees that outputs a predictive value and is robust against over-fitting. This algorithm has two parameters, mtry and ntree, which may vary to improve its performance. The first represents the number of input variables chosen at random in each division and the second the number of trees.  
Random Forest obtains a class vote of each tree and proceeds to classify according to the vote of the majority. We show the functioning of Random Forest in Algorithm 1.  
```
1 Let \(N\) be the number of training cases, and \(M\) the number of variables.
2 Select the value of \(m\), in order to determine the decision in a given node, which must be less than the value of \(M\).
3 Vary and choose \(N\) for the tree (completing all training cases) and use the rest of the test cases to estimate the error.
4 For each node of the tree, randomly choose \(m\). Obtain the vote of each tree and classify according to the vote of the majority.
```  
**Algorithm 1**Random Forest for classification  
In classification processes, the default value for m is calculated by \(\sqrt{p}\) or [log2 \(p\)], where \(p\) is the number of features. Random Forest provides the VIMs method, through which it is possible to rank the importance of variables in regression or classification problems.  
Variable Importance Measures (VIMs). VIMs, based on CART classification trees [PERSON] (1986), allows calculation of the weight to identify key attributes or features. In VIMs there are two embedded methods for measuring variable importance proposed by [PERSON]: Mean Decrease Impurity importance (MDI) and Mean Decrease Accuracy (MDA). MDI ranks each feature importance as the sum over the number of splits that include the feature, proportionally to the number of samples it splits; this method is used in classification cases and applied the Gini index to measure the node impurity [PERSON] (1986); [PERSON] (1986). Random Forest also uses the Gini index for determining a final class in each tree. MDA is also called the permutation importance and is based on out-of-bag (OOB) [PERSON] (1986) samples to measure accuracy; this method is suitable for regression problems [PERSON] (1986). In this work we used MDI with Gini index to classify comments in cases of cyber-aggression, which is defined by:  
\[G(t)=1-\sum_{k=1}^{Q}p^{2}(k|t) \tag{1}\]  
where \(Q\) is the number of classes, \(p(k|t)\) is the estimated class probability for feature \(t\) or node \(t\) in a decision tree and \(k\) is an output class.  
At the end of the process, VIMs calculate a score for each variable, normalized by the standard deviation. The higher the score, the more important the feature. In this work, we used \(R\)[PERSON] (1986) and applied the \(randomForest\)[PERSON] (1986) library to develop the classification model.  
OneR. OneR stands for One Rule. OneR is a rule-based classification algorithm. A classification rule has the form: if attribute1 <relational operator> value1 <logical operator> attribute2 <relational operator> value2 <...> then decision-value. OneR generates one rule for each predictor in the data set, and among them all, it selects the rule with the smallest total error as the only one rule [49]. One advantage of rules is that they are simple for humans to interpret.