Despite the widespread adoption of TMR or PMR and the formulas designed to sufficiently cover the cows' requirements, individual dairy cows' milk production varies significantly. The liver is one of the most important organs in cow lactation metabolism and plays an essential role in the initiation of lactation. This study aimed to investigate the potential key genes in the liver contributing to the different milk production. We enrolled 64 cows and assigned them to high or low milk yield (MY) groups according to their first 3 weeks of milk production. We performed RNAseq for 35 liver samples with 18 from prepartum and 17 from postpartum cows. The continuous milk yield observation showed a persistently higher milk yield in high MY cows than low MY cows in the first 3 weeks. High MY cows showed better feed conversion efficiency. We identified 795 differentially expressed genes (DGEs) in the liver of high MY cows compared with low MY cows, with up-regulated genes linked to morphogenesis and development pathways. Weighted gene co-expression network analysis (WGCNA) revealed four gene modules positively correlating with milk yield, and protein and lactose yield (p < 0.05). Using the intersected genes between the four gene modules and DEGs, we constructed the linear mixed-effects models and identified six hub genes positively associated and two hub genes negatively associated with milk yield (Coefficients > 0.25, p < 0.05). Random forest machine learning model training based on these eight hub genes could efficiently predict the milk yield (p < 0.001, R2 = 0.946). Interestingly, the expression patterns of these eight hub genes remained remarkably similar before and after parturition. The present study indicated the critical role of liver in milk production. Activated processes involved in morphogenesis and development in liver may contribute to the higher milk production. Eight hub genes identified in this study may provide genetic research materials for dairy cow breeding.