The alarming pace of environmental degradation necessitates the treatment of wastewater from the oil industry in order to ensure the long-term sustainability of human civilization. Electrocoagulation has emerged as a promising method for optimizing the removal of chemical oxygen demand (COD) from wastewater obtained from oil refineries. Therefore, in this study, electrocoagulation was experimentally investigated, and a single-factorial approach was employed to identify the optimal conditions, taking into account various parameters such as current density, pH, COD concentration, electrode surface area, and NaCl concentration. The experimental findings revealed that the most favorable conditions for COD removal were determined to be 24 mA/cm2 for current density, pH 8, a COD concentration of 500 mg/l, an electrode surface area of 25.26 cm2, and a NaCl concentration of 0.5 g/l. Correlation equations were proposed to describe the relationship between COD removal and the aforementioned parameters, and double-factorial models were examined to analyze the impact of COD removal over time. The most favorable outcomes were observed after a reaction time of 20 min. Furthermore, an artificial neural network model was developed based on the experimental data to predict COD removal from wastewater generated by the oil industry. The model exhibited a mean absolute error (MAE) of 1.12% and a coefficient of determination (R2) of 0.99, indicating its high accuracy. These findings suggest that machine learning-based models have the potential to effectively predict COD removal and may even serve as viable alternatives to traditional experimental and numerical techniques.