With the rapid development of sensor technology, machine learning, and the Internet of Things, wireless sensor networks have gradually become a research hotspot. In order to improve the data fusion performance of wireless sensor networks and ensure network security in the event of external attacks, this paper proposes a wireless sensor optimization algorithm model, involving wireless sensor networks, the Internet of Things, and other related fields. This paper first analyzes the role of the Internet of Things in wireless sensor networks, studies the localization mechanism and hierarchy of the Internet of Things based on wireless sensor networks, and improves the LE-RLPCCA (Position Estimation Robust Local Retention Criteria Correlation Analysis) localization algorithm model based on sensor grids. This paper discusses the problems of machine learning in wireless sensor networks, constructs a sensor-based machine learning model, and designs a data fusion algorithm for a wireless sensor networks’ machine learning model. The application of wireless sensors in engineering mechanics experiments is summarized, and the optimization algorithm model of the wireless sensor in engineering mechanics experiments is proposed. The analysis results show that the average accuracy of the DKFCM-FSVM (Density aware Kernel-based Fuzzy C-means Clustering algorithm Fuzzy Support Vector Machine) algorithm in detecting five behaviors is 0.997, 0.992, 0.904, 0.996, and 0.946, respectively, and the accuracy in detecting different behaviors is the best, 0.005, 0.01, 0.003, and 0.006 respectively. It achieves the lowest false positive rate in the detection of different behaviors, and the average false positive rate is 0.004, 0.003, 0.003, 0.008, and 0.005, respectively, which shows that the DKFCM-FSVM algorithm model of wireless sensor networks in engineering mechanics experiments is the optimal solution. The work of this paper has good reference value for the application of wireless sensor networks and the optimization of engineering mechanics experimental methods and is helpful for further research of sensor technology.