Identifying gamma rays and rejecting the background of cosmic-ray hadrons are crucial for very-high-energy gamma-ray observations and relevant scientific research. Based on the simulated data from the square kilometer array (KM2A) of LHAASO, eight high-level features were extracted for the gamma/hadron classification. Machine learning (ML) models, including logistic regression, support vector machines, decision trees, random forests, XGBoost, CatBoost, and deep neural networks (DNN) were constructed and trained using data sets of four energy bands ranging from 10 12 to 10 16 eV, and finally fu...