Ketosis is a common metabolic disorder in dairy cows and occurs mainly during early lactation. Blood β-hydroxybutyrate (BHB) is widely used for diagnosis, but large-scale testing is limited by sampling requirements and cost. We therefore studied lactating Holstein cows from 12 large-scale dairy farms in central China. Milk samples, milk composition traits, and milk mid-infrared (MIR) spectra were collected through the Dairy Herd Improvement (DHI) testing system from April 2019 to December 2022, and ketosis diagnoses were obtained from farm health records; samples were labeled as healthy or ketotic based on the temporal relationship between diagnosis and sampling. A total of 2206 samples were used to build the calibration and validation datasets, in which five feature wavenumber selection methods and five machine learning algorithms were compared. Ketotic cows had a higher milk fat percentage and fat-to-protein ratio and a lower protein and lactose percentage (p < 0.01). The best combination was PLS-DA based on 104 CARS-selected wavenumbers, which achieved a sensitivity of 0.83, a specificity of 0.79, a balanced accuracy of 0.81 and an area under the receiver operating characteristic curve (AUC) of 0.88 in validation. MIR spectroscopy combined with machine learning can therefore support large-scale ketosis phenotyping within the DHI system.