High-quality development in the manufacturing industry is often accompanied by high energy consumption. The accurate prediction of the energy consumption of computer numerical control (CNC) machine tools, which plays a vital role in manufacturing, is of great importance in energy conservation. However, the existing research ignores the impact of multi-factor energy losses on the performance of machine tool energy consumption prediction models. The existing models must be selected and verified several times to determine the appropriate hyperparameters. Therefore, in this study, a machine tool energy consumption prediction method based on a mechanism and data-driven model that considers multi-factor energy losses and hyperparameter dynamic self-optimization is proposed to improve the accuracy and reduce the difficulty of hyperparameter tuning. The proposed multi-factor energy-loss prediction model is based on the theoretical prediction model of machine-tool cutting energy consumption. After creating the model, a hyperparameter search space embedding a tree-structured Parzen estimator (TPE) was designed based on Hyperopt to dynamically self-optimize the hyperparameters in the deep neural network (DNN) model. Finally, two sets of experiments were designed for verification and comparison with the theoretical and data models. The results showed that the energy consumption prediction performances of the proposed hybrid model in the two sets of experiments were 99% and 97%.