# Energy Consumption Prediction for Drilling Pumps Based on a Long Short-Term Memory Attention Method
## 3 Results and Discussion  
### Data Processing  
The data processing procedure in this study includes the following steps: outlier detection, data filtering, data normalization, and data segmentation. Each step is described in detail below. Outlier detection and removal were conducted using the RANSAC (Random Sample Consensus) algorithm. RANSAC is a robust model fitting method particularly suitable for datasets containing a significant number of outliers. It iteratively selects a random subset of the data and fits a model, classifying data points as inliers or outliers based on their distance from the model. In this study, pump pressure (MPa), inlet flow rate (L/min), and pump power (kW) were selected as input features for outlier detection using the RANSAC algorithm. As shown in Figure 3, during each iteration, a random set of data points is selected to establish a linear regression model relating pump pressure, inlet flow rate, and pump power. The deviation of all data points from this model is then calculated, and those with deviations below a certain threshold are classified as inliers, while the rest are classified as  
Figure 2: Attention mechanism. outliers. This process is repeated multiple times to ensure that the selected set of inliers is as large as possible. In this study, the main parameters of the RANSAC algorithm include the maximum number of iterations and the deviation threshold. The maximum number of iterations was set to 1000 to ensure the algorithm's convergence, and the deviation threshold was set to a small value based on the data distribution to strictly select the inliers. After processing with the RANSAC algorithm, a total of 1034 data points were identified as outliers due to their large deviations from the majority of the data points and were removed. Finally 8715 valid data points were retained for subsequent model training and analysis. Figure 4 shows the utilization of a sliding window method to collect real-time pumping power data. Each sliding window corresponds to a distinct data stream (e.g., \(X_{0}\), \(X_{1}\), and \(X_{2}\)), with varying time intervals for each window. This design ensures the independence of data during training and testing processes by preventing overlaps across windows. The training and testing of each data stream are conducted independently, and within a single data stream, there is no overlap between the test data windows and training data windows. To ensure data independence and the validity of the test results, we train and test each data stream separately, rather than combining all data streams into a single model for training. Therefore, each data stream's model is trained in isolation, without any interconnection or influence from other streams. This approach allows the model to capture patterns across different time periods while avoiding potential issues arising from high correlation among neighboring samples. By ensuring the separation of training and testing data, the model can be trained without exposure to test data, enhancing its reliability in predicting future unseen data. This design reduces the risk of data leakage and ensures the validity of validation and testing processes. Moreover, using samples from different sliding windows provides a more comprehensive assessment of the model's generalization capability, preventing bias in test results. Figure 3: Application of the RANSAC mechanism. Data normalization was conducted to unify the value ranges of different features and eliminate the impact of scale differences on model training. In this study, we chose the Max normalization method based on the following considerations: during data preprocessing, we had already removed outliers from the dataset; therefore, we believed that Max normalization would not be significantly affected by any remaining extreme values. This method effectively scales all features to a similar range, ensuring that each feature contributes more evenly to the loss function during model training and accelerates the model's convergence.