# Optimizing Methanol Injection Quantity for Gas Hydrate Inhibition Using Machine Learning Models
## 3 Results and Discussion  
### Analysis of Model Results  
Figures 1-6 show the 50 Monte Carlo simulation scores (adj. R\({}^{2}\), MAE, and RMSE) for the training and testing stages, respectively, to assess the reliability of the XGBoost, RF, DT, and KNN models in estimating the methanol quantity needed. The scores in Figures 1-3 corresponded only with the training dataset (80% of the dataset), and were used to illustrate the robustness of the models. The consistently high adj. R\({}^{2}\) and low MAE and RMSE values indicated the overall good prediction ability of the proposed machine learning methods. The models were able to more accurately infer from the data after 50 runs and, overall, it was established that XGBoost had the highest predictive power. Based on the adj. R\({}^{2}\) in the training stage, the models could be ordered according to performance as follows: KNN < DT < RF < XGBoost. The RF model had similar performance metrics to XGBoost. The KNN model showed less predictability and consistency than the other three ML models. Figures 1-3 show the adj. R\({}^{2}\), MAE, and RMSE values, respectively, of the training phase. The x-axis represents the sequence of scrambled datasets produced by the Monte Carlo method (1-50). For comparison, the vertical axis represents the values of the assessment criteria. The test stage, as illustrated in Figures 4-6, revealed that, based on the decreasing order of the prediction performance of the models, the models ranked as follows: XGBoost, RF, DT, and KNN. This was similar to the preceding analyses. Overall, the XGBoost model demonstrated very strong predictive performance across 50 simulations, indexed by the relatively high adj. R\({}^{2}\) values and low RMSE and MAE values. In contrast, the XGBoost model was much more consistent compared with the other three models given that, even after 50 iterations, the amplitude of the variation of all indicators was negligible. Figure 1: Adj. R\({}^{2}\) across 50 Monte Carlo simulations (training data). Figure 2: MAE across 50 Monte Carlo simulations (training data). Figure 4: Adj. R\({}^{2}\) across 50 Monte Carlo simulations (testing data). Figure 5: MAE across 50 Monte Carlo simulations (testing data). Figure 3: RMSE across 50 Monte Carlo simulations (training data). The optimal performance features of the four ML models on the database are displayed in Table 2, which includes the testing and training datasets. Lower values for the MAE and RMSE implied a better predictive accuracy of the models. A higher adj. R\({}^{2}\) value indicated a stronger fit of the model to explain the variance observed in the data. The results showed that, other than the KNN model, all ML models performed significantly better. The XGBoost and RF models had the lowest values for MAE and RMSE. This finding suggests that both methods could provide more accurate estimates of methanol volume with a small margin of error. Overall, this work highlights the better performance of the DT algorithm compared with the KNN model, as indicated by the high adj. R\({}^{2}\) and low MAE values. This confirmed that the models could be used to provide reliable methanol quantity values for samples of gas pipelines. The scatter plots in Figures 7-10 show the correlation between the measured methanol quantities and the predicted values from the XGBoost, RF, DT, and KNN models for gas pipeline samples. The XGBoost model exhibited exceptional predictive performance for determining the minimum methanol quantity required for hydrate inhibition. During the training phase, it achieved a mean absolute error (MAE) of 0.3693, indicating an average prediction error of just 0.3693 units compared with the actual methanol quantities in the training dataset. This low MAE underscored XGBoost's ability to closely fit the training data. In the testing phase, the MAE slightly increased to 0.943, reflecting a modest rise in prediction errors when applied to unseen data, yet still demonstrating high accuracy.