Accordingly, different deep learning and machine learning models such as long- and short-term memory, temporal recurrent units, random forests, artificial neural networks, and K-nearest neighbors are used for CPI forecasting. The prediction performances of the models on the test data were evaluated with RMSE, MSE, MAE, MAPE, and R^2 error statistics. The results show that the Gateway Recurrent Unit model outperforms the Long and Short Term Memory, Random Forest, Neural Network, and K-Nearest Neighbors models. Compared to the other four models, the RMSE, MSE, MAE, MAPE, and R^2 values performed better in the recurrent unit model. In addition, it has been observed that deep learning and machine learning models can be used effectively in the field of inflation in consumer price index forecasting. These results provide an effective method of CPI forecasting, which is an important component of economic forecasting and inflation management. From an academic perspective, this study demonstrates the applicability of deep learning and machine learning models in economics and finance. In practice, it provides a valuable tool for economic and financial decision-makers and illuminates the way for future similar studies.