{'fraction_non_alphanumeric': 0.031189849550221943, 'fraction_numerical': 0.01571277055426798, 'mean_word_length': 4.570678336980307, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Real-Time Prediction of Equivalent Circulation Density for Horizontal Wells Using Intelligent Machines

Equivalent circulation density (ECD) is an important part of drilling fluid calculations. Analytical equations based on the conservation of mass and momentum are used to determine the ECD at various depths in the wellbore. However, these equations do not incorporate important factors that have a direct impact on the ECD, such as bottom-hole temperature, pipe rotation and eccentricity, and wellbore roughness. This work introduced different intelligent machines that could provide a real-time accurate estimation of the ECD for horizontal wells, namely, the support vector machine (SVM), random forests (RF), and a functional network (FN). Also, this study sheds light on how principal component analysis (PCA) can be used to reduce the dimensionality of a data set without loss of any important information. Actual field data of Well-1, including drilling surface parameters and ECD measurements, were collected from a 5–7/8 in. horizontal section to develop the models. The performance of the models was assessed in terms of root-mean-square error (RMSE) and coefficient of determination (R2). Then, the best model was validated using unseen data points of 1152 collected from Well-2. The results showed that the RF model outperformed the FN and SVM in predicting the ECD with an RMSE of 0.23 and R2 of 0.99 in the training set and with an RMSE of 0.42 and R2 of 0.99 in the testing set. Furthermore, the RF predicted the ECD in Well-2 with an RMSE of 0.35 and R2 of 0.95. The developed models will help the drilling crew to have a comprehensive view of the ECD while drilling high-pressure high-temperature wells and detect downhole operational issues such as poor hole cleaning, kicks, and formation losses in a timely manner. Furthermore, it will promote safer operation and improve the crew response time limit to prevent undesired events.


INTRODUCTION
Drilling fluid hydraulics has played an important role in well design when drilling a vertical or extended reach well. Therefore, accurate model and optimized drilling fluid hydraulics are crucial to allow engineers to properly design a well profile, thereby improving drilling efficiency, reducing risks, and decreasing nonproductive time (NPT). Additionally, it empowers the drilling crew to fully examine the downhole conditions and identify potential problems such as drill string washout, plugged nozzles, and the presence of a gas kick in the well.
Equivalent circulation density (ECD) is an important aspect of drilling fluid hydraulics which helps in avoiding kicks and drilling fluid losses, particularly in deep high-pressure hightemperature (HPHT) wells, where the temperature is significant and the margin between pore pressure and fracture pressure is minute. 1 Drilled cuttings can increase the effective drilling fluid density and reduce fluid flow area, which in turn increases the value of the ECD. Thus, ECD calculations can be used as a baseline to monitor hole cleaning in real time while drilling.
Hydraulics programs have been widely used to evaluate the detailed hydraulic calculations that are required in planning, execution, and post-well review phases of drilling a well. The user has the option to select which rheological model (Bingham plastic, Power-law, Herschel−Bulkley) the hydraulic calculations are based on. Each rheological model, however, requires different data inputs, which can be obtained from a full lab test. These parameters are then fed into the software to compute the drilling fluid hydraulics and its associated parameters such as ECD. It has been observed that there is a discrepancy between computed data and the data recorded in the field. 2 One factor contributing to the inconsistency between calculated and actual drilling hydraulics is the assumption that the rheological properties of the drilling fluid are independent of pressure and temperature. 1 This can be valid in shallow wells, where temperature changes are insignificant, and hence, the rheological variations are small. Furthermore, the mathematical equations used to calculate the drilling hydraulics entail a set of assumptions such as 2−4 (i) concentric annular and circular sections, (ii) laminar and turbulent flow, where plug flow is considered as laminar flow, while transition flow is neglected, and (iii) steady-state flow, where fluid properties at any single point in the system do not change. Such potentially unrealistic assumptions cannot be fulfilled in all drilling conditions. 5 In HPHT wells, evaluations and analyses of the effect of temperature and pressure on drilling hydraulics and kick probability are necessary. 1,6 Rommeveit and Bjorkevoll 1 developed two models, a static ECD model and a dynamic ECD model, which incorporate the temperature profile along the wellbore and allow the mud properties to be dependent on pressure and temperature. They concluded that the models made it possible to make realistic and reliable evaluations of any operational concerns during drilling especially when, for example, pit gain and standpipe pressure (SPP) deviate from the predictable value. Scheid et al. 7 performed an experiment to evaluate the frictional pressure loss through pipes, annuli, and accessories such as pipe tool joint and stabilizers to estimate the drilling hydraulic calculations and the corresponding ECD with four types of drilling fluid. They stated that the results obtained in the study can be used in the drilling industry for accurate drilling hydraulic calculations.
Dokhani et al. 3 concluded that eccentricity (ϵ), which describes how off-center a pipe is in an open hole or casing, affects frictional pressure loss and hence the ECD for Herschel−Bulkley fluid.
Eccentricity reduces overall frictional pressure loss if ϵ is >0.1 and it will be neglected if ϵ is 0.8. 8−10 Moreover, Dokhani et al. 3 evaluated the effect of pipe rotations on frictional pressure loss. They observed that a drilling fluid's apparent viscosity decreases as pipe rotation increases; hence, overall frictional loss decreases. This phenomenon is a result of the shear-thinning properties of Herschel−Bulkley fluid. 11 Dokhani et al. 3 also recommended considering the effect of roughness of the wellbore wall to have a more accurate estimation of drilling hydraulic calculations such as ECD.
A more accurate and reliable way to evaluate the ECD is to use a downhole pressure sensor, which consists of highaccuracy pressure gauges to measure the annular pressure. The sensors provide important real-time downhole pressure information which will allow the drilling crew to make a faster and better decision. 12 However, such sensors are extremely expensive. 13 The literature review shows that major discrepancies exist between actual drilling hydraulic values and those predicted by previously accepted mathematical equations. In addition, several studies have suggested consideration of other factors, including pipe eccentricity, wellbore roughness, pressure and temperature, and pipe rotation speed to improve the accuracy of drilling hydraulic calculations. This, however, would mandate intensive mathematical intervention.
An alternative approach to estimating the ECD with higher accuracy is by using artificial intelligence (AI) and machine learning (ML), 13,14 which map the inputs and outputs based on a defined algorithm. 15 AI is efficient enough to minimize human efforts in various areas and does not necessitate fundamental knowledge of physics and science. AI has become an important subject in the drilling industry, 15 where streaming data are continuously structured from the surface, downhole sensors and logging. AI and ML allow for new methods to learn from these data to mitigate drilling challenges, describe trends in real time, and automate drilling. 16 This study introduces three intelligent techniques to predict the ECD which can help in reducing the overall cost of drilling operation by not using downhole pressure sensors for future offset wells. The developed models would give the drilling crew the capability to monitor hole cleaning, maintain the wellbore pressures in horizontal extended-reach wells in real-time, and reduce the risk of formation fracture and collapse. Furthermore, they can improve the warning time to detect kicks to maintain well control.
1.1. Application of AI and ML in the Drilling Industry. Drilling is a major aspect of the oil and gas industry which is considered to be highly expensive and risky. Therefore, tools that can improve the drilling operation at a low cost are essential. There are some applications related to AI and ML in drilling operations such as 17 well planning, rate of penetration (ROP) optimization, well integrity, detecting problems, procedure decision making, and pattern recognition.
The large number of publications on the application of AI and ML in the drilling industry indicate that AI and ML can potentially reduce drilling costs and promote safety at the rigsite. 16,17 Abdelgawad et al. 13 used SPP, ROP, and mud weight (MW) as input parameters to predict the ECD using an artificial neural network (ANN) and an adaptive neuro-fuzzy inference system (ANFIS) in an 8−1/2 in. vertical hole section. The two models predicted the ECD with a correlation coefficient (R) of 0.99 and AAPE of 0.22%. Alkinani et al. 14 collected data from more than 2000 wells located around the world and used an ANN to build a model to predict the ECD. The input parameters for the model were flow rate, MW, nozzles total flow area, plastic velocity, revolutions per minute, weight on bit (WOB), and yield point. Bayesian Regularization (BR) was used as a training algorithm because it had the highest R 2 (0.982).
Alsabaa et al. 18 used ANFIS to predict the rheological properties of invert emulsion mud in real time. Al-Yami et al. 19 used Bayesian Belief Network (BBN) to establish an intelligent drilling system based on different fluid and reservoir properties. This tool can be utilized to train young engineers in different drilling perspectives such as well control, underbalanced drilling, drilling fluid, and cementing best practices. Ahmadi 20 simulated the performance of various types of drilling fluid's rheology under different conditions using a support vector machine (SVM) with good agreement between lab results and prediction. Elkatatny et al. 21 used an ANN, which incorporates drilling fluid and drilling mechanical properties, to predict ROP with high accuracy. Elkatatny et al. 22 used actual field data to build an ANN to predict the top-depth of four geological formations in real time while drilling. The best results were obtained when scaled conjugate gradient backpropagation (TRAINSCG) with 20 neurons was used. The input parameters used in the study to develop the model were the mechanical drilling parameters including ROP, Q, RS, SPP, torque, and WOB.
1.2. Support Vector Machines. SVMs are supervised ML models that analyze data for classification or regression problems 17 and can lead to a high performance in particular ACS Omega http://pubs.acs.org/journal/acsodf Article applications. 23 Moreover, SVMs have advantages over other ML algorithms, including generalization capability, less learning time, and strong interference capacity. 24,25 SVMs move the data from a low dimension to a high dimension, denoted as kernel space, to find a support vector classifier, that is, hyperplane, that minimizes the number of misclassified data points. 17,26,27 The hyperplane is defined as the plane with a maximal margin of separation between two classes, and the distance between the hyperplane and the nearest data point from either set is known as the margin. Support vectors are the data with the closest distance to the hyperplane. These are difficult to classify, 26 which is why the hyperplane with the maximum margin is the best separator.
To transform the data to kernel space, SVMs use kernel functions to systematically find the support vector classifiers in higher dimensions. When kernels are used to transform the feature vectors from input space to kernel space for linearly nonseparable data sets, the kernel matrix computation requires computational resources. The popular kernel functions are 27 linear kernel function, polynomial kernel function, Gaussian RBF, and randomized blocks analysis of variance (ANOVA RB) kernel.
The selection of kernel functions is essentially dependent on the nature of the data set. The linear kernel ranks behind the polynomial kernel, and it is useful in large sparse data vectors. On the other hand, the polynomial kernel is commonly used in image processing. While the ANOVA RB kernel is generally used for regression tasks, the Gaussian RBF is mostly applied if the user lacks prior knowledge. 27 1.3. Random Forests. The RF is an ensemble learning technique that can be used for classification and regression problems. 28 The RF combines hundreds or thousands of decision trees and trains each one on a slightly different set of observations. It splits nodes in each tree considering a limited number of features, in a process called bootstrapping. 29 The final prediction of the RF is made by averaging the predictions of each tree in a process called aggregation. When a bootstrap sample is made from the data set, about one-third of the samples from the original data set are not included. 30 These samples are called out-of-bag data and are used to measure internally the accuracy of the RF. The RF outperforms a single decision tree because of its ability to limit overfitting without substantially increasing the margin of error. 29 1.4. Functional Network. A functional network (FN) is a generalization of an ANN, which can be accomplished by using multiple arguments and learnable functions, that is, in a FN, the activation functions associated with neurons are not fixed but learned from data. 31 In an ANN, the weights associated with the neurons must be learned, while they are suppressed in a FN. 25 Another characteristic of a FN is that the specification of the initial topology could be based on the features of the problem. Therefore, knowledge about the problem can help in developing the network structure.
1.5. Principal Component Analysis. PCA is a useful statistical technique that has many applications in many fields and is a common technique for finding patterns in a data set with high dimensions. 32 The objective of PCA is to reduce the dimensionality of a large data set of variables or features into a smaller one without the loss of any important information. 33 PCA finds a lower dimensional space (W) to transform the data (X = [x 1 , x 2 ,..., x N ]) from a higher dimensional space (R M ) to a lower dimensional space (R k ),where N represents the total number of observations (rows in a data set) and x i represents the ith observation. Each observation is represented by M features or variables (columns in a dataset), that is, each observation is represented as a point in M-dimensional space. 34 A PCA space for a data set that contains a number of features K has K principal components. These K principal components are uncorrelated, orthonormal, and represent the direction of the maximum variance. 33 The first component, (PC 1 ϵ R M ), always represents the maximum variation of the data; (PC 2 ϵ R M ) represents the second-largest variation of the data, while (PC n ϵ R M ) represents the least variation of the data. 32,33 The principal components that represent more than 90% of the variation in a data set are often considered.
The following sequence shows how to calculate PCs using the Covariance Matrix Method for a given data set (X = {x 1 , x 2 , ..., x N }): • Compute the mean of all variables • Subtract the mean of each variable from all observations corresponding to that variable • Compute the covariance matrix for the centered data set were obtained from surface real-time transmitter sensors, while ECDs were obtained from a pressure-while-drilling (PWD) sensor. A total of 3567 data points of ECD were obtained at the same depth of the drilling surface parameters. Table 1 shows the statistical parameters of the whole data set. Q ranges from 250 to 296.5 GPM; HL ranges from 256 to 286 klbf; ROP ranges from 3.5 to 59.6 ft/h; RS ranges from 59 to 141  Figure 1 compares the linear relationship of the input parameters used to train the model with the ECD. Figure 1 shows that HL, SPP, and T have a strong relationship with the ECD, that is, 0.71, 0.87 and 0.85, respectively. Q has a moderate linear relationship with an ECD of −0.38. On the other hand, ROP, RPM, and WOB have relatively a low relationship of −0.13, 0.1, and 0.11, respectively.
2.2. Data Splitting. In ML, it is necessary to build a model that makes accurate predictions for future data. Thus, the data set is divided into two portions, training and testing sets. The training set is used to ensure that the machine recognizes patterns in the data set, while the testing set is used to evaluate how well the machine can predict unseen data based on its training.
In this analysis, seven surface drilling parameters were used as independent variables (inputs): Q, HL, ROP, RS, SPP, WOB, and T, while ECD was used as a dependent variable (output). The data set was randomly split, with a ratio of 80:20. Eighty percent of the data was selected for training to ensure that the models capture most of the ECD variation while drilling with various surface drilling parameters. The training set has 2742 data points, while the testing set has 827 data points. Tables 2 and 3 show the statistical parameters of the training and testing sets, respectively.
2.3. Model Building. Python library's Scikit-Learn was used to build the SVM model. The SVM parameters, known as hyperparameters (e.g., regularization parameter C, gamma, and kernel type), were tuned using a built-in function in Scikit-Learn known as GridSearchCV to evaluate the improvement and performance of the SVM. Two types of kernel, RBF and linear were tried while varying the value of C from 0.001 to 1000 and the type of gamma (i.e. auto and scale). Likewise, Scikit-Learn was used to develop the RF model. The model parameters, including the maximum depth of the tree "max_depth", the maximum features to be considered when splitting the node in each tree "max_features", and the number of the trees in the forest" n_estimators", were tuned using GridSearchCV. Different values of max_depth from 3 to 21 and three types of max_features (i.e., auto, sqrt, and log 2 ) were tried while varying the n_estimator from 3 to 150. The rest of the model parameters, including minimum_samples split, minimum_sample leaf, maximum_leaf nodes, and minimu-m_impurity, were kept as default values. MATLAB code was used to build the FN model. Two methods, FN Forward-Backward Method (FNFBM) and FN Exhaustive-Backward Method (FNEBM), were studied with two types of relationship: linear and nonlinear.
2.4. Using PCA for Dimensionality Reduction. Standardizing a data set refers to shifting the distribution of each variable to have a unit scale, that is, a mean of zero and a standard deviation of one, which is a necessary step for the PCA algorithm. The values of the input parameters were standardized using the following equation where Y is the normalized input parameter, X is the input parameter to be normalized, and σ is the standard deviation of the input variable. Then, Python library's Scikit-Learn was used to apply the PCA algorithm to the input variables of the data set of Well-1. The transformation to PCA space was completed in three steps: (i) instantiate the PCA by passing the number of principal components to the constructor, (ii) call the fit, which will find the covariance matrix, the eigenvectors, and eigenvalues of the covariance matrix, and (iii) transform the data set into the PCA space. Then, the transformed data set was fed into another RF model for training and testing. The PCA-based RF model improvement and performance while using different numbers of PCs were evaluated.

RESULTS AND DISCUSSION
3.1. Model Assessment. The SVM model performance with different parameters (C, gamma, and kernel type) is presented in Table 4. The optimal parameters for each kernel type were obtained using GridSearchCV. Table 4 shows that the SVM model with the RBF kernel had the highest R 2 and the lowest root-mean-square error (RMSE) compared to the linear kernel. The SVM with the RBF kernel predicted the ECD with an R 2 of 0.97 and an RMSE of 0.54 in the training set, while the R 2 and RMSE were 0.97 and 0.58, respectively, in the testing set. On the other hand, the SVM with the linear kernel predicted the ECD with an R 2 of 0.95 and an RMSE of 0.71 in the training set and with an R 2 and RMSE of 0.95 and    Table 5. Figure 3a,b are cross-plots of the actual and predicted ECD of the training and testing sets, respectively.
The FN model performance with different methods and relationship types is presented in Table 6. Table 6 shows that the best results were obtained when FNEBM was used with a nonlinear relationship type. The model predicted the ECD with an RMSE of 0.44 and R 2 of 0.99 in the training set and with an RMSE of 0.45 and R 2 of 0.99 in the testing set. Figure  4a,b denotes cross-plots of the actual and predicted ECD of the training and testing sets, respectively, when FNEBM with a nonlinear relationship was used.
The optimum results of each model are summarized in Table 7. Table 7 shows that the RF is the most accurate model in estimating the ECD with a low RMSE and high R 2 in the training and testing sets. The FN was the second most accurate model, followed by the SVM as the least accurate model.
3.2. Validation of the Developed RF. The best model, RF, was selected to be validated using a total of 1152 unseen data points collected from Well-2. The compatibility of the input parameters in Well-2 was checked to ensure they are in the same range as the data set, which was used to train the RF model. Table 8 shows the statistical parameters of the data set of Well-2. The RF predicted the ECD in Well-2 with an RMSE of 0.35 and an R 2 of 0.95. Figure 5 shows the actual and predicted ECD as a function of the depth index of Well-2. The depth index was used to hide the actual depth of the drilled section.
3.3. PCA for Dimensionality Reduction. The input variables of the original data set collected from Well-1 were standardized using eq 1. Then, the data set was transformed to PCA space using Python library's Scikit-Learn. Table 9 shows a sample of the training set after transformation to PCA space.
It is important to study the variation that each PC accounts for in the data set to perform dimensionality reduction. Figure  6 is a screen plot, which is a graphical representation of the percentages of the variation that each PC accounts for in the whole data set. The first thing to notice is that the first principal component PC 1 6 , and PC 7 combined explain only 6.51% of the total variation in the data set. Thus, even though the points in the data set form a cloud in a dimensional space (R 7 ), PCA shows that these points cluster near a four-dimensional plane (R 4 ) spanned by PC 1 , PC 2 , PC 3 , and PC 4 . The contribution of each variable (Q, HL, ROP, RS, SPP, WOB, or T) in each principal component is presented in Table  10. How all of this needs to be interpreted? For example, in studying PC 1 , the second entry "0.58", HL, is the largest, which means a change in one unit of HL tends to affect the ECD more than a change of one unit of Q, ROP, RS, SPP, WOB, or T. The first entry "0.52", which corresponds to Q, is the next most important factor in determining the ECD. On the other hand, the second last entry "0.14", WOB, is the least important     The PCA-based RF model performance in predicting the ECD in the same testing set used in Section 3.1, while using different numbers of PCs, was evaluated and compared with the SVM and FN, which were trained and tested using 100% variation of the data set (i.e., seven dimensions) as discussed in Section 3.1. Table 11 shows that as the number of PCs for the data set increases from one principal component to four principal components, the R 2 and RMSE improve. However, when more than four principal components were considered, RMSE increased. The PCA-based RF with only four principal components outperformed the SVM, with an RMSE of 0.54 and R 2 of 0.97. In addition, the PCA-based RF with only four principal components performed almost similar to the FN that had an RMSE of 0.45 and R 2 of 0.99. Furthermore, even if only two dimensions PC 1 and PC 2 (63.10% of variation) were considered, the PCA-based RF would perform almost similar to the SVM with an RMSE of 0.63 and R 2 of 0.96. In other words, the PCA-based RF model with four inputs (i.e., PC 1 , PC 2 , PC 3 , and PC 4 ) performed better than the SVM and almost similar to the FN, which were trained with seven inputs (i.e. Q, HL, ROP, RS, SPP, WOB, and T). This showed how the PCA technique is powerful enough to transform the data set from a higher dimensional space to a lower dimensional space without loss of any important information, which in turn increases the speed of the training process for a model.   Figure 6. Percentages of the variation that each PC accounts for in the whole data set.