# Random forest Algorithm for the Classification of Spectral Data of Astronomical Objects
## 3 Results and Discussion
### Performance Measures  
In machine learning, every pattern classification experiment consists of two phases: training and testing. After applying the selected validation method to the dataset (in our case, we have selected Hold-out 80-20), the pattern classification algorithm is executed on the training set E (in our case, the proposed random forest algorithm). Then, the trained algorithm is presented with one-by-one test patterns from the set P. The classification algorithm will output one of two options: correct or incorrect.  
With these values, it is possible to calculate the measure that expresses the classification algorithm's performance on the specified dataset with the selected validation method [30]. In this paper, we will apply the proposed random forest algorithm to the SDSS-DE14, SDSS-DE16, and SDSS-DE17 datasets, with partitions generated by the Hold-out 80-20 validation method.  
One of the simplest and easiest to calculate performance measures is accuracy [44], defined as the ratio of correct predictions to the total number of test patterns. The value of accuracy ranges from 0 to 1.  
\[accuracy=\frac{number\ of\ correct\ predictions}{number\ of\ test\ patterns} \tag{6}\]  
The accuracy performance measure considers classification errors in general. However, in the calculation of accuracy, the costs of different types of errors are not considered; that is, it is equally important to misclassify a pattern from class 1 as misclassifying a pattern from class 2. In an imbalanced dataset, there is a real risk that a classifier (no matter how good it is) will exhibit a bias towards the majority class, ignoring the minority class. The solution to this problem is addressed using the confusion matrix, which allows for considering the particularities of the decisions made by state-of-the-art classifiers.  
To work with the confusion matrix, it is necessary to define one of the classes as positive and the other class(es) as negative. From there, four possibilities arise that are shown below in a confusion matrix for two classes:  
Figure 2: Schematic illustration of the result of the validation method.  
Where:  
* _TP_: True Positive
* _TN_: True Negative
* _FP_: False Positive
* _FN_: False Negative  
True Positive (_TP_) represents the number of positive patterns that are correctly classified as positive. In contrast, True Negative (_TN_) represents the number of negative patterns correctly classified as negative. False Positive (_FP_) is the number of negative patterns that are incorrectly classified as positive, and False Negative (_FN_) is the number of positive patterns that are incorrectly classified as negative.  
The confusion matrix for three or more classes is simply an extension of the scheme in Figure 3.  
From the four elements of the confusion matrix, it is possible to define many performance measures. Next, we present the four performance measures used in the experiments of this paper, including the expression of accuracy in terms of the four elements: _TP_, _FN_, _FP_, and _TN_[45; 46].  
\[sensitivity=\frac{TP}{TP+FN} \tag{7}\]  
\[specificity=\frac{TN}{FP+TN} \tag{8}\]  
\[balanced\ accuracy=\frac{sensitivity+specificity}{2} \tag{9}\]  
What happens to the values of accuracy and balanced accuracy when the value of _IR_ increases?  
Noticeably, as the value of _IR_ increases, the performance measure balanced accuracy becomes more reliable than accuracy, due to the tendency of most classifiers towards highly imbalanced datasets: classifiers exhibit bias towards the majority class.  
The balanced accuracy performance measure is more reliable than accuracy because it considers the contributions of both classes in the average [46].