In this study, the near infrared spectroscopy (NIRS) technology was used to quantitatively detect talcum powder in 82 wheat flour samples. Based on anomaly detection, sample division, and spectral preprocessing, four models were established to predict the content of talcum powder in wheat flour. Among them, the performance of Bayesian ridge regression (BRR) combined with second derivative (2D) was proved to be the best. In addition, 46 effective features were selected using a multilevel feature method combining improved particle swarm optimization (PSO) and genetic algorithm (GA). At this time, the coefficient of determination (R2_PRE), root mean square error of prediction (RMSEP), and relative percent difference (RPD) values of the BRR model on the prediction set reached 0.9802, 0.8914, and 6.9263. The results showed that NIRS technology was feasible in detecting the content of talcum powder in wheat flour. At the same time, the effectiveness of multilevel method was better than that of single‐level method, and the performance of improved POS was better than that of PSO.