# Drilling Condition Identification Method for Imbalanced Datasets
## 5 Experiment and Analysis of Drilling Condition Identification
### Data Processing and Model Design  
The dataset used in this study originates from the actual logging data of 14 adjacent wells in Block H of an oilfield, all from the same drilling cycle, totaling 194,035 data points. The model is built using Python (3.11) and the TensorFlow (2.17) deep learning framework, with sklearn (1.5.2) for data evaluation and processing. Additionally, matplotlib (3.9.2) and seaborn (0.13.2) are utilized for visualizing the training process. To address anomalies or missing data caused by equipment failures, communication issues, and other factors, the boxplot analysis method was employed for data cleaning. First, missing and blank values were removed, and outliers were handled. To prevent differences in the dimensions of drilling parameters from affecting feature importance and correlation, the Z-score normalization method was applied to the data prior to feature engineering. The original dataset contained 25 parameters, including wellbore depth, vertical depth, bit position, and drilling pressure. After feature engineering using a weighted symmetric uncertainty-based feature selection method, 12 drilling parameters were selected. The original parameters and the parameters retained after feature selection are shown in Figure 8.  
In conjunction with the drilling work logs, the data were labeled with nine drilling conditions, with the proportion of each condition in the original dataset and the corresponding label assignments shown in Table 1. The proportion differences between the conditions in the original data were significant, and the imbalance rate between the majority and minority classes in this dataset reached 13.43. When using the sliding-window-based SMOTE oversampling method, the choice of window size and time step significantly affects the results. The window size determines the local segment range of the data during each resampling, while the time step determines the distance the sliding window moves each time. To preserve the dependencies between adjacent time points in the drilling time-series data, the time step is set to half of the window size. To select an appropriate sliding window size, the window size is increased from 5 to 40, and the synthetic dataset is input into the classifier for training. The relationship between  
Figure 8: Original parameters and retained parameters after feature selection. the model's classification \(F1\) score and the sliding window size is shown in Figure 9. The final window size is determined to be 24, and after applying the sliding-window-based SMOTE method for oversampling, the class distribution of the different drilling conditions becomes balanced. To optimize the model performance, hyperparameter configurations were adjusted based on key indicators such as precision, recall, loss value, and training time on the test set. The detailed hyperparameter settings are shown in Table 2. For the BiLSTM model, the number of hidden units is set to 128. To enable the network to better handle long-term dependencies in sequential data, the BiLSTM model outputs the full sequence as input for subsequent recurrent layers. The data undergo a dropout layer with a dropout rate of 0.5 both when inputting to the GRU model and when outputting, which randomly discards half of the neurons to prevent over-reliance on specific neurons, thus improving the model's generalization ability. The number of hidden units in the GRU model is also set to 128. To reduce data dimensionality and highlight the most important feature information, two fully connected layers are used with 128 and 64 neurons, respectively. The activation function for both layers is ReLU (Rectified Linear Unit). Finally, the data are input into a softmax layer for classification, with the output having nine categories corresponding to nine different drilling condition labels. The model is compiled using the Adam (Adaptive Moment