The ibuprofen (IB) residuals in water resources are classified as toxic and non-biodegradable contaminants. In the previous study, the Zn-decorated S,P,B co-doped C2N (Zn-SPB@C2N) nanosheet exhibited significant effectiveness in adsorbing IB from aqueous solutions. However, the operating conditions were not optimized for the adsorption process. The current study modeled the adsorption of IB onto Zn-SPB@C2N nanosheets employing central composite design (CCD) and machine learning (ML) methods under various operating conditions. The operating conditions included adsorbent mass, initial IB concentration, and pH. The CCD model revealed a mean squared error (MSE) value of 36.56. The ML investigations showed MSE values of 28.12 for the artificial neural network (ANN), 10.12 for the decision tree (DT), 8.68 for the linear regression (LR), and 3.70 for the random forest (RF) models. The RF model demonstrated high reliability in predicting IB removal across various conditions compared to other methods. Using the RF model, a maximum removal efficiency of 98 % was achieved under the optimized operating conditions, containing a pH of 7, an initial concentration of 59 mg/L, and an adsorbent mass of 0.020 g.