Minimum miscibility pressure (MMP) is one of the most important parameters for designing CO2 enhanced oil recovery (EOR) and associated storage in depleted oil reservoirs. The injection gas stream often contains a certain concentration of impurities such as N2, H2S, and CH4 depending on the source of CO2. These impurities have different effects on CO2 MMP, but there is a lack of widely accepted approaches to account for these effects on MMP calculation. In this study, a series of activities were conducted to develop a machine learning (ML)-based methodology for determining MMP for CO2 with various impurities. A database containing 234 CO2 MMP test sets with around 5000 data points was built based on the reported experimental measurements in the public domain. The database was then subgrouped by three specific criteria: CO2 concentration in the injection gas, type of impurities in the injection gas, and heavier hydrocarbon content in the oil. This subgrouping was essential to capture the impact of different factors on CO2 MMP. An ensemble ML approach with seven ML models, including random forest, adaptive boosting, light gradient boosting machine, extreme gradient boosting (XGBoost), stacking, artificial neural network, and voting regressor, was employed to calculate MMP based on the subgrouped database. The hyperparameters of these ML models were optimized by the grid search technique to minimize the relative errors between calculated and measured MMP values. The performance of each algorithm was assessed using three regression metrics: average absolute relative error (AARE), R-squared score (R2), and root mean square error (RMSE). All of these metrics exhibited satisfactory values for the optimized ML models. The average values of R2, RMSE, and AARE were 0.962, 1.571, and 4.55%, respectively, for the three subgroups, indicating a high accuracy of MMP calculations using the optimized ML models. The XGBoost model emerged as the top performer across the three metrics, with an R2 of 0.979, an AARE of 2.835%, and an RMSE of 1.183 for a dataset with 190 cases. The overall high level of accuracy confirmed the reliability of these ML models in calculating MMP for CO2 with different impurities as well as the importance of optimization in the modeling process.