Simple SummaryIn recent years, farming the black soldier fly (BSF)Hermetia illucens(L.) (Diptera: Stratiomydiae) has gained popularity across the globe due to its usefulness mainly in animal feed production and waste management. The short cycle time taken to rear the BSF and the high protein content present in its larvae makes it a suitable source of feed for a variety of animals (e.g., poultry, fish, and pigs); the livestock bred as food for humans. However, despite the farming of black soldier fly larvae (BSFL) as a source of feed, its production levels are low and do not meet the existing market demand. This study explored data science and machine learning modeling approaches to discern optimal rearing conditions for improved BSFL farming. The random forest regressor machine learning algorithm gave the best prediction results. The algorithm also ranked the variables that contributed most to the prediction of the expected larvae weight. Given the studied rearing conditions, the prediction algorithm can discern and predict the expected weight of BSFL to be harvested. Tuning the production system parameters according to the order of the ranked parameters can further optimize the production of BSFL. BSFL are a source of feed for the animals that are a source of food for humans; therefore, this research contributes to alleviating food insecurity.AbstractAs the world population continues to grow, there is a need to come up with alternative sources of feed and food to combat the existing challenge of food insecurity across the globe. The use of insects, particularly the black soldier fly (BSF)Hermetia illucens(L.) (Diptera: Stratiomydiae), as a source of feed stands out due to its sustainability and reliability. Black soldier fly larvae (BSFL) have the ability to convert organic substrates to high-quality biomass rich in protein for animal feed. They can also produce biodiesel and bioplastic and have high biotechnological and medical potential. However, current BSFL production is low to meet the industry’s needs. This study used machine learning modeling approaches to discern optimal rearing conditions for improved BSF farming. The input variables studied include the cycle time in each rearing phase (i.e., the rearing period in each phase), feed formulation type, length of the beds (i.e, rearing platforms) at each phase, amount of young larvae added in the first phase, purity score (i.e, percentage of BSFL after separating from the substrate), feed depth, and the feeding rate. The output/target variable was the mass of wet larvae harvested (kg per meter) at the end of the rearing cycle. This data was trained on supervised machine learning algorithms. From the trained models, the random forest regressor presented the best root mean squared error (RMSE) of 2.91 and an R-squared value of 80.9%, implying that the model can be used to effectively monitor and predict the expected weight of BSFL to be harvested at the end of the rearing process. The results established that the top five ranked important features that inform optimal production are the length of the beds, feed formulation used, the average number of young larvae loaded in each bed, feed depth, and cycle time. Therefore, in that priority, it is expected that tuning the mentioned parameters to fall within the required levels would result in an increased mass of BSFL harvest. These data science and machine learning techniques can be adopted to understand rearing conditions and optimize the production/farming of BSF as a source of feed for animals e.g., fish, pigs, poultry, etc. A high production of these animals guarantees more food for humans, thus reducing food insecurity.