# Optimizing Methanol Injection Quantity for Gas Hydrate Inhibition Using Machine Learning Models
## 3 Results and Discussion
### Analysis of Model Results
The RMSE further supported this with values of 0.6023 (training) and 2.066 (testing), indicating that larger errors, while present, remained minimal and manageable. The adj. R\({}^{2}\) metric, which measured the proportion of variance in the target variable explained by the input features, was 0.999 for both the training and testing phases. This near-perfect score suggests that XGBoost captured 99.9% of the variability in methanol requirements, reflecting its \begin{table}
\begin{tabular}{c c c c c c c c c} \hline \hline \multirow{2}{*}{**Metric**} & \multicolumn{2}{c}{**XGBoost**} & \multicolumn{2}{c}{**RF**} & \multicolumn{2}{c}{**DT**} & \multicolumn{2}{c}{**KNN**} \\ \cline{2-9}  & **Training** & **Testing** & **Training** & **Testing** & **Training** & **Testing** & **Training** & **Testing** \\ \hline Adj. R\({}^{2}\) & 0.999 & 0.999 & 0.999 & 0.997 & 0.998 & 0.994 & 0.996 & 0.992 \\ MAE & 0.369 & 0.943 & 2.238 & 5.680 & 2.339 & 5.695 & 3.648 & 6.07 \\ RMSE & 0.602 & 2.06 & 4.369 & 6.13 & 5.12 & 6.594 & 5.619 & 10.475 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Best performance metrics of four models for training and testing datasets. Figure 6: RMSE across 50 Monte Carlo simulations (testing data). robust fit with the training data and excellent generalization to the test set. These results highlight XGBoost's superior reliability and precision in predicting methanol quantities across diverse pipeline conditions. Figure 8: Predicted vs. measured minimum methanol for hydrate inhibition by RF (test dataset). Figure 7: Predicted vs. measured minimum methanol for hydrate inhibition by XGBoost (test dataset). Figure 10: Predicted vs. measured minimum methanol for hydrate inhibition by KNN (test dataset). Figure 9: Predicted vs. measured minimum methanol for hydrate inhibition by DT (test dataset). The random forest (RF) model also demonstrated a strong predictive capability, although it underperformed compared with XGBoost. During training, RF achieved an MAE of 2.238, meaning its predictions deviated from the actual methanol quantities by an average of 2.238 units, a respectable error margin that indicated good alignment with the training data. However, in the testing phase, the MAE rose to 5.680, suggesting a noticeable drop in accuracy when generalizing new data. This trend was mirrored in the RMSE values, which increased from 4.369 (training) to 6.13 (testing), indicating that RF was more susceptible to larger errors with unseen data compared with XGBoost. Despite this, RF maintained high adj. R\({}^{2}\) values of 0.999 (training) and 0.997 (testing), demonstrating that it explained nearly all the variance in methanol quantities during training and retained strong explanatory power for the test set. Although RF performed well overall, its higher error metrics relative to XGBoost suggest that it was less consistent and precise for this application. The decision tree (DT) model delivered solid but less impressive results compared with XGBoost and RF. In the training phase, it recorded an MAE of 2.339, reflecting an average error of 2.339 units and indicating reasonable accuracy in fitting the training data. During testing, the MAE increased to 5.695, revealing a decline in predictive accuracy for unseen data, consistent with DT's tendency to overfit simpler tree structures. The RMSE values reinforced this pattern, rising from 5.12 (training) to 6.594 (testing), which pointed to a greater incidence of larger errors compared with the ensemble methods. The adj. R\({}^{2}\) scores of 0.998 (training) and 0.994 (testing) remained high, indicating that DT explained most of the variance in methanol quantities and retained a decent generalization ability. However, its performance lagged behind XGBoost and RF, likely due to its lack of ensemble averaging, which limited its capacity to handle the dataset's complexity as effectively. The k-nearest neighbors (KNN) model showed the weakest performance among the four models evaluated.