Panax notoginseng slices (PNS) are prepared from the taproot of a rare Chinese herbal plant, Panax notoginseng. The price and efficacy of PNS change depending on its grade, but substandard PNS are more prevalent in the Asian market. In this study, a portable near‐infrared spectrometer was used to collect the spectra of 240 PNS samples divided into four grades. The spectral data were preprocessed by the Savitzky–Golay (SG) filter to eliminate noise interference. Principal component analysis (PCA), competitive adaptive reweighted sampling, and variable combination population analysis were used to extract the feature variables of the spectral data. The selected feature variables were used to establish least squares support vector machine (LSSVM), support vector machine (SVM), and extreme learning machine (ELM) classification models. To further improve the classification accuracy of the most effective of these models, a grey wolf optimizer (GWO) was introduced, and particle swarm optimization (PSO) as well as genetic algorithm (GA) were used to conduct comparative analyses. The results showed that PCA provided accurate identification information of different PNS grades and that the classification effect of the LSSVM model was better than that of the ELM and SVM models. During the optimization process, the optimization accuracy of the GWO was better than that of the PSO and GA systems. Therefore, the optimal classification model was established as GWO–PCA–LSSVM, and the classification accuracy of the test set was 91.67%. Therefore, portable near‐infrared spectroscopy technology can be used to identify the grade of PNS effectively.