Tobacco is a critical economic crop, yet its cultivation heavily relies on chemical pesticides, posing health risks to consumers, therefore, monitoring pesticide residues in tobacco is conducive to ensuring food safety. However, most current research on pesticide residue detection in tobacco relies on traditional chemical methods, which cannot meet the requirements for real-time and rapid detection. This study introduces an advanced method that combines hyperspectral imaging (HSI) technology with machine learning algorithms. Firstly, a hyperspectral imager was used to obtain spectral data of tobacco samples, and a variety of spectral pre-processing technologies such as mean centralization (MC), trend correction (TC), and wavelet transform (WT), as well as feature extraction methods such as competitive adaptive reweighted sampling (CARS) and least angle regression (LAR) were used to process the spectral data, and then, grid search algorithm (GSA) is used to optimize the support sector machine (SVM). The optimized MC-LAR-SVM model achieved a pesticide classification accuracy of 84.1%, which was 9.5% higher than the original data model. The accuracy of the WT-TC-CARS-GSA-SVM model in the fenvalerate concentration classification experiment was as high as 91.8 %, and it also had excellent performance in other metrics. Compared with the model based on the original data, the accuracy, precision, recall, and F1-score are improved by 8.3 %, 8.2 %, 7.5 %, and 0.08, respectively. The results show that combining spectral preprocessing and feature extraction algorithms with machine learning models can significantly enhance the performance of pesticide residue detection models and provide robust, efficient, and accurate solutions for food safety monitoring. This study provides a new technical means for the detection of pesticide residues in tobacco, which is of great significance for improving the efficiency and accuracy of food safety detection.