This study presents a novel hybrid deep neural network (DNN) with the White Shark optimization (WSO) algorithm to predict and optimize the gas sensing performance of Ni0.6−xMgxCo0.4Fe2O4 nanoparticles at different sizes (x = 0.1, 0.2, 0.3, 0.4, and 0.5). In order to create Ni0.6−xMgxCo0.4Fe2O4, the sol–gel process was employed, with x varying from 0.1 to 0.5 ppm. This study utilized precursors such as Ni(NO3)2·6H2O, Mg(NO3)2·6H2O, Co(NO3)2·6H2O, and Fe(NO3)3·9H2O. Response–recovery curves were analyzed, and a hybrid DNN-WSO model was created to predict gas sensing properties for Ni0.6−xMgxCo0.4Fe2O4 ferrite materials with different Mg levels. Fit statistics like the sum of squares (SSE), R-squared (R2), degrees of freedom (DFE), adjusted R2, and RMSE were calculated. In XRD analysis, the (311) peak shifted from 35.6561° to 35.5614° for Ni0.6−xMgxCo0.4Fe2O4. At 200 °C, the sensor is more responsive to NO2 gas than NH3 gas, with Ni0.6−xMgxCo0.4Fe2O4(x = 0.5) showing the highest response due to increased oxygen adsorption sites for gas oxidation. Smaller particle sizes (x = 0.1) in SEM analysis exhibited well-defined nanocrystalline structures with high crystallinity and smooth surfaces, enhancing sensitivity. The TGA results confirm the stability and functionality of the proposed materials up to the operating temperature of 250 °C. The Ni0.6−xMgxCo0.4Fe2O4(x=0.2) concentration exhibited the best predictive accuracy with high R2, high adjusted R2, enhanced DFE, and low RMSE. The hybrid DNN-WSO algorithm effectively predicts and optimizes gas sensing performance, which is significant for advancing efficient gas sensor development. [ABSTRACT FROM AUTHOR]