# Hybrid Machine Learning-Statistical Method for Anomaly Detection in Flight Data
## 3 Local Outlier Factor
### Implementation
#### 3.2.6. A Hybrid Statistical Threshold Analysis  
As discussed in the original paper by [PERSON] et al. (2018), any data point \"A\" deep inside a cluster (dense region) with a density comparable to its neighbors or higher than its neighbors is an inlier. The LOF value of such point A will be =1 or <1. The paper [PERSON] et al. (2018) also gives a detailed discussion on points with LOF value > 1 and labeled as outliers. Such points may be near the periphery of the cluster or dense region (LOF value slightly greater than 1) or far outside the cluster (LOF value significantly greater than 1). The original LOF paper [PERSON] et al. (2018) defines very well the lower and upper bound of an outlier in terms of LOF values. Whilst, in theory, any point with a LOF value > 1 is an outlier, in practice, there are often peripheral points that are not necessarily anomalous. Often these can be explained by experts in a particular field. Therefore, our aim here is to set a threshold that defines how far a point should be from a cluster of points (dense region) to be categorized as an outlier. The value of this threshold is, to an extent, dependent on the field of application. In the flight data analysis, while it may be acceptable to have false positives, which would then be further reviewed by experts, false negatives are not tolerated as these may provide a false sense of safety. In order to achieve this, the LOF results were discussed with aviation experts. In our research, we came across several false positives whereby flights with LOF values greater than 1, despite deviating from the rest of the fleet, would still fit under the standard operating procedures and therefore posed no threat to safety. In order to decrease false positives, a method for fine-tuning the LOF threshold value was required. The upper limit of LOF value greater than 1, which could safely be a normal flight, was to be determined as a threshold. Deciding this threshold arbitrarily and based on feedback from a human expert is not only a laborious process but also introduces human bias. Furthermore, it was also found that this threshold changes for each group of flights and for each arrival airport. In order to decide this threshold, statistical methods such as the z-score method, bell curve method, [PERSON]'s method and median method were explored. Figure 7. Optimal \(k\) vs. number of flights for three airports. Statistical analysis helps to find important parameters of the dataset. Some of these parameters, such as median, lower quartile, upper quartile and outliers, can easily be represented by constructing a boxplot for continuous univariate data by using [PERSON]'s method. [PERSON]'s test was chosen as it is distribution independent. The rules of the method are as follow:  
1. The Inter Quartile Range (IQR) is the difference between the upper quartile (Q3) and the lower quartile (Q1);
2. Inner fences are fixed at a distance of 1.5 times IQR below Q1 and above Q3. They are given by: \[[\text{Q1}-(1.5\times\text{IQR}),\text{Q3}+(1.5\times\text{IQR})];\] (6)
3. Outer fences are fixed at a distance of 3 times IQR below Q1 and above Q3. They are given by: \[[\text{Q1}-(3\times\text{IQR}),\text{Q3}+(3\times\text{IQR})];\] (7)  
Any data point lying between these fences is a possible outlier. Any data point beyond the outer fence is a probable outlier. For the detection of anomalous flights, inner fences are considered. Figure 8 shows a group of 103 flights from the same tail number arriving at the same airport. LOF scores are plotted on the x-axis, and flight count is plotted on the y-axis. Out of 103 flights, 63 flights have a LOF score greater than 1. Analyzing all these 63 flights is very time-consuming. As per [PERSON]'s rule of the inner fence (Equation (6)), the threshold comes to a LOF value of 1.1690. There are now only five flights that are greater than this threshold. These are the real outliers. While validating these results, the human expert (experienced pilot) found that four out of these five outliers were true positives.