# A Quality Control Method for High Frequency Radar Data Based on Machine Learning Neural Networks
## 2 Materials and Methods
### Prediction-Based Anomaly Detector
#### 2.2.3 Anomaly Detection  
This section introduces the anomaly detection process utilized in our study and the associated evaluation metrics. As shown in Figure 2, when the data are fed into the trained model, they produce an output as a time series. The difference between this predicted output and the original input forms the'residual time series'. Ideally, instances of anomalies should be evident as significant deviations in this residual series, while normal data points are expected to have minor variations from the predicted values. To identify anomalies, we establish a threshold for the residual time series. Data points with residuals below this threshold are classified as normal, while those with residuals exceeding the threshold are identified as anomalies.  
In our study, the threshold is determined through an evaluation of anomaly detection performance on the test dataset. For imbalanced datasets such as radar ocean-current data, the performance of anomaly detection algorithms is typically assessed using the Precision-Recall Curve (PRC) and the F-score. The vertical axis of the PRC represents  
Figure 4: Bidirectional LSTM neural network architecture diagram.  
precision, while the horizontal axis represents recall. Precision, Recall, and the F-score are defined as follows:  
\[\text{Precision}=\frac{\text{TP}}{(\text{TP}+\text{FP})} \tag{7}\]  
Precision: The ratio of true positives (correctly identified anomalies) to the sum of true positives and false positives (false alarms), reflecting the algorithm's accuracy in anomaly detection.  
\[\text{Recall}=\frac{\text{TP}}{(\text{TP}+\text{FN})} \tag{8}\]  
Recall: The ratio of true positives (correctly identified anomalies) to the sum of true positives and false negatives (missed anomalies), indicating the algorithm's capability to detect all anomalies.  
\[\text{F}-\text{score}=2\times\frac{\text{Precision}\times\text{Recall}}{ \text{Precision}+\text{Recall}} \tag{9}\]  
F-score: The harmonic mean of precision and recall. It offers a comprehensive measure of the algorithm's performance, factoring in both false positives and false negatives.  
In our preceding discussion, we introduced three evaluation metrics for anomaly detection. For the quality control of high-frequency radar data, both precision and recall are of paramount importance. Precision represents the model's ability to correctly label actual anomalies, ensuring the reliability of our anomaly identifications. Meanwhile, recall assesses the model's thoroughness in capturing all genuine anomalies, emphasizing the completeness of the identification process. However, precision and recall often exhibit opposing trends as the detection threshold varies. Over-emphasizing precision may minimize false alarms but at the risk of potentially overlooking some genuine anomalies. Conversely, prioritizing recall could lead to a higher likelihood of labeling normal data as anomalous. To harmonize these two essential metrics and ensure optimal quality control for our radar data, we adopt the F-score. This comprehensive measure takes into account both precision and recall, ensuring that our quality control neither misses genuine anomalies nor raises excessive false alarms.