Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 8s (2025) 48 https://internationalpubls.com A Python Framework for Pest Management and Crop Yield prediction Yogesh V. Gandge1, Dr. P Sandhya2 Department of MCA,BKIT Bhalki, Department of Studies in Computer Applications,VTU PG Centre,Mysuru,India. Article History: Received: 29-10-2024 Revised:13-11-2024 Accepted:20-12-2024 Abstract: In recent years, agriculture has become increasingly important as the world's population continues to grow. The demand for food grains is constantly on the rise; this exerts more pressure on farmers to maximize their crop yields. One of the biggest challenges the farmers face is managing pests and maintaining soil fertility. Farmers apply pesticides only after witnessing the pest on the crop. By this time the pest has already made an impact on the crop leading to crop loss. Traditional methods of pest management and preserving soil fertility are time-consuming and less effective.In this paper, a Python framework has been developed that can help farmers maximize their crop yield by predicting the attack of the pest on the crop and the most suitable period for spraying the pesticide.Timely and precise prediction of outbreak of pest can help in controlling the pest and improving crop yield. DM is used to forecast pest attacks. Time series data on the pest trap values is collected from the website. Here the pest considered is American Ball worm adult and the crop considered is cotton. The weekly data is collected from 1991 to 2000.On this data after preprocessing it is subjected to DM model. For prediction 10 years data is considered. ARIMA model is developed and employed on this time series data.The accuracy of the forecasting model is verified by using RMSE value. We will go through the benefits of using this framework and describe how it can make farming more efficient and productive. Keywords: Crop Yield Maximization; Python Framework; Pest Management; Soil Fertility Prediction; Agricultural Data Analysis; Precision Farming; Prediction Modeling; Integrated Pest Management; Soil Nutrient Analysis; Yield Enhancement. 1. Introduction In recent years AI & ML has emerged as the pioneering force for data analysis and prediction. AIML has found its application in every sector of farming and agric business. DM is used widely in yield prediction, pest prediction, soil fertility prediction, soil classification and identifying the correlation among the attributes of the dataset obtained from soil analysis.DM is the process of identifying hidden knowledge from the dataset which was not discovered till now. The knowledge which is discovered through DM is based on the scientific model which is properly trained and tested. Once the model is developed then such model can work on any new dataset with similar domain. Such models can be used for classification, prediction and identifying correlation among the attributes. Through DM latest information can be discovered from the huge dataset deriving from the soil analysis and such information can be provided to the concerned stakeholders well in advance so that resources can be planned and corrective action can be taken beforehand. In DM various models are developed for data analysis, classification and prediction. In this paper the study is focused on pest value prediction and the best time for the application of the pesticide to the crop. In fig 1 the steps followed in knowledge discovery is depicted. Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 8s (2025) 49 https://internationalpubls.com Fig1:Steps in Knowledge discovery Predictions beforehand will help the farmers in planning the resources and the optimal resource utilization with fewer burdens on their economy. The major hurdle in enhancing crop yield is pest which drastically affects the yield and the economic state of farmer [1].There are different types of pest or insects which effect different crops. Pest and insects are having their own life cycle. Here the goal is not to completely eradicate the pest but to restrict the intensification of the pest to such a level that its presence should not harm the crop flowers, leaves and seed buds. Integrated pest management is one best solution for managing pest and improving yield. The emergence of pest is generally induced by various climatic factors like humidity, windspeed, temperature, etc[2]. Growth of plant and its yield is directly affected by two categories of insects. One type will affect the leaves, flowers and fleshy fruit buds. And another type affect by spreading viral or fungal infection to the crop [3].When the climatic conditions are conducive for the pest then there will be a high growth of pest and there will be an increase in the activity of pest which leads to crop loss. Growth of pest depends upon the climatic parameters[4]. Early forecasting of pest outbreak would be very much beneficial in avoiding the loss in yield and for optimum resource utilization [5]. Global warming and climate change are posing threat to the agric sector [6][7].Transboundary crop diseases affect the yield of the crop in numerous ways [8]. Predicting beforehand will provide leverage to the farmers in handling the pest problem in more effective manner. This forecasting not only provides the pest outbreak time but also it helps in farmers selecting more pest tolerant variety of seeds, planning in crop rotation etc. Not only does this will help the farmers but also it will help the government agencies and private agencies to develop pest tolerant seeds and production of such pesticides which are less dangerous to the ecosystem. Yield of cotton at several places has been declined due to unplanned pest management system[9][10].Pest attack not only affects the crop yield but also it affects the country’s economy[11][12].Due to sudden change in the climatic factors it provides an environment where in pest can breed and dwell[6] .Therefore an early warning mechanism would be more beneficial.DM and ML can help in providing early warning mechanism .In the absence of the proper pest management the farmers face huge crop loss[13]. To effectively provide the early warning mechanism on pest outbreak a model is proposed which makes use of the huge dataset on the pest trap values. Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 8s (2025) 50 https://internationalpubls.com 2. Related work D.Markovic et al. [14] presented prediction of pest by considering temperature and humidity. They obtained an accuracy of 76.5%. Muhammad Salman et al. [15] considered climatic factors like temperature, relative humidity and rainfall. Their study used parameters like temperature, relative humidity, and rain sensors along with ANN to predict pest attack. They obtained a result of 85.6% accuracy. Earlier study focused on presence of pest on crop using image processing. Few researchers also predicted the pest attack using image processing. Ornela et al. utilized Explainable Boosting Machine, which uses earth observation vegetation indices, numerical weather predictions and insect trap catches to predict the pest attack and its severity. They implemented their model to predict bollworm pest attack on cotton crop in Greece[16]. [17] Matheus et.al. reviewed the techniques and scientific approach used by sensors for mechanical detection and monitoring of pests. Their focus is on the methods for identification of pests using infrared sensors, audio sensors and image-based classification. Tamoghna Ojha et al. [18] focused on the importance of IoT in agriculture practices. They presented a framework to address challenges that are faced in agriculture. They also focused on energy optimization while using the framework. Changqing et al. [19] proposed a greenhouse environment monitoring solution for continuous provisions of environment conditions desired for the crop. The authors have used layered technologies to monitor the environmental parameters. Demin Gao et.al. [20] presented that through IoT and drones agriculture fields can be properly monitored for identifying pest attack on the crop. Huge data is collected through IoT sensors and drones. Data models for pest prediction were developed. They implemented this framework in the Yangtze River Zone of China. And they concluded that wheat is vulnerable to disease when the temperature is between 14 to 16 degree Centigrade and high precipitation decreases the spread of wheat powdery mildew. [21] Min Dai et.al. presented YOLOv5 based on CNN for recognizing pest on plants. They implemented the algorithm on the pest images and obtained the result of 95.7% accuracy. [22] Mohamed Esmail Karar et.al. presented a mobile application to robotically classify pests using deep-learning. They used faster region-based convolutional neural network For recognizing pests based on cloud computing. This study has been successfully validated on five types of pests; namely Aphids, Cicadellidae, Flax Budworm, Flea Beetles, and Red Spider. The presented algorithm R- CNN had highest accuracy with results of 99.0%. Presently IoT is used in every sector, even for pest identification, prediction and for controlling the spread of pest IoT can be utilized. IoT can also be used for continuously sensing the various factors like temperature, humidity, moisture in soil. These factors affect the growth of pest. Pest or insect attack on crops is a very severe problem which every farmer across India faces. Several pest attack identification using image based processing are used but they are effective only https://itiis.org/journals/tiis/digital-library/category-search?author=Muhammad%20Salman%20Latif Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 8s (2025) 51 https://internationalpubls.com after the pest has already created loss on crop. Moreover there is a strong correlation between the environment factors and the sudden outbreak of pest. Some studies have been carried out based on the climatic factors as well. But this is also not sufficient .Therefore there is a need for the pest outbreak prediction beforehand so that crop loss can be reduced by using time series data. 3. Methodology The structural design of the projected solution i.e. the projected pest forecasting model is shown below in fig.2. The pest forecasting is based on the time series data. The data collected is regarding pest trap values since 1991 to 2000.The crop and the pest which is considered in this study are cotton and American Bollworm-Adult respectively. The geographical area considered for the study is Lam. The data collected is weekly basis; this data is averaged to month wise data. This dataset is used to train the model. After the training of the model it is used to predict the outbreak of the pest. Fig 2.Architecture of Pest Prediction Approach 4. Implementation The major focus of the earlier research was to discover and classify the pest which affects the crop. But in this research we are forecasting the occurrence of the pest much before the pest attack. Due to such forecasting the farmers can plan well ahead with regard to spraying of pesticides. The dataset is collected from the source http://www.icar-crida.res.in:8080/naip/AccessData.jsp Algorithm: Prediction of the pest Attack Input: Dataset consisting of attributes Date and Pest trap count Output: Forecasting of Pest outbreak Step 1: Reading the data. Before reading the data, Date is positioned as the index. The pest catch value attribute is the mean value of four weeks in a month Step 2: Preprocessing Presence of Null values and outliers are checked and are removed. https://links.rediff.com/cgi-bin/red.cgi?red=https%3A%2F%2Flinks%2Erediff%2Ecom%2Fcgi%2Dbin%2Fred%2Ecgi%3Fred%3Dhttp%253A%252F%252Fwww%252Eicar%252Dcrida%252Eres%252Ein%253A8080%252Fnaip%252FAccessData%252Ejsp%26amp%3BisImage%3D0%26amp%3BBlockImage%3D0%26amp%3Brediffng%3D0%26amp%3Brogue%3D0c6d13476716e5d900ccde13fad6caa3b0cbcf78%26amp%3Brdf%3DVXlUOVQ0AGBVe11hBiNTWAc9XjRfNQ%3D%3D&isImage=0&BlockImage=0&rediffng=0&rogue=27c03d4748ea131241966fa2203e5782d7c62247&rdf=UHwFaFU1A2MALlBsASQHDFBqBW8MZg== Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 8s (2025) 52 https://internationalpubls.com Step 3: Data is tested for the stationarity using Augmented Dickey Fuller Test. If the data is not stationary then differencing is carried out. Otherwise go to Step 4. Step 4: Identify the best possible values for the parameters: ARIMA(p, d, q) Using autoarima package, the significance values with the lowest AIC will be used for the p, d, q parameters of ARIMA model. The values for the parameters p,d,q vary from 0 to 2. The optimal values obtained for p,d,q are (2,0,0) with lowest AIC value. Values for the p, d, q, are determined where p = amount of autoregressive terms. d = amount of nonseasonal differences. q = amount of moving-average terms. Step 5: Data records are partitioned into training data and evaluating data in the proportion (80:20) Step 6: Fitting the ARIMA model with the parameters identified(p, d, q) By using the most optimal values calculated in the step 4, the representative model is fitted on the data records. Step 7: Model predicts the pest values from 31-1-2023 to 31-12-23 Step 8: Validating the result The forecasting is provided for the upcoming 12 months. RMSE is used for validating the model. 5. Results and Discussion The dataset consists of the weekly pest trap value. In this dataset, for every month the mean of the pest trap value for all the four weeks in a month is calculated. The data collected is since 1991 to 2000.As per the result obtained it is clearly visible that from the April to Aug month there is high pest occurrence. It may be due to the slight increase in temperature. Therefore it could be predicted that in cotton crop pest attack will be more during April to July. Conclusion Machine learning model is prepared and used for forecasting of pest attack. This forecasting model utilizes pest trap values on cotton crop. The pest which is under the study is American Ball worm adult. The prediction is based on the weekly pest trap values. This model will provide the accurate information about the pest attack well in advance by which the farmers can plan for the resources. At the same time this model will help the farmers to plan ahead of time, before the actual impact of pest. ARIMA model is proposed and used, this model can also be implemented on any crop. The model presented here showed the least AIC value and the least RMSE value. Future Work In the present study only the time series data on pest trap value is considered but in the future work other attributes like temperature and humidity can also be considered along with pest trap value. By Communications on Applied Nonlinear Analysis ISSN: 1074-133X Vol 32 No. 8s (2025) 53 https://internationalpubls.com appending temperature, humidity values in the pest trap values dataset more inside information can be discovered. Refrences [1] H. Lee, A. Moon, K. Moon, and Y. Lee, ‘‘Disease and pest prediction IoT system in orchard: A preliminary study,’’ in Proc. 9th Int. Conf. Ubiquitous Future Netw. (ICUFN), Jul. 2017, pp. 525–527 [2] R. M. Nadeem, A. Jaffar, and R. M. Saleem, ‘‘IoT and machine learning based stem borer pest prediction,’’ Intell. Autom. Soft Comput., vol. 31,no. 3, pp. 1377–1392, 2022 [3] J. Cho, J. Choi, M. Qiao, C.-W. Ji, H.-Y. Kim, and K.-B. Uhm, ‘‘Automatic identification of tobacco whiteflies, aphids and thrips in greenhouse using image processing techniques,’’ Red, vol. 346, p. 244, Jan. 2007. [4] J. Lu, R. Ehsani, Y. Shi, J. Abdulridha, A. I. de Castro, and Y. Xu, ‘‘Field detection of anthracnose crown rot in strawberry using spectroscopy technology,’’ Comput. Electron. Agricult., vol. 135, pp. 289–299, Apr. 2017. [5] Y. Shang and Y. Zhu, ‘‘Research on intelligent pest prediction of based on improved artificial neural network,’’ in Proc. Chin. Autom. Congr. (CAC),Nov. 2018, pp. 3633–3638 [6] O. Z. Aregbesola, J. P. Legg, L. Sigsgaard, O. S. Lund, and C. Rapisarda, ‘‘Potential impact of climate change on whiteflies and implications for the spread of vectored viruses,’’ J. Pest Sci., vol. 92, no. 2, pp. 381–392, Mar. 2019. [7] R. M. Saleem, R. Kazmi, I. S. Bajwa, A. Ashraf, S. Ramzan, and W. Anwar, ‘‘IoT-based cotton whitefly prediction using deep learning,’’ Sci. Program., vol. 2021, pp. 1–17, Jul. 2021. [8] N. Materne and M. Inoue, ‘‘IoT monitoring system for early detection of agricultural pests and diseases,’’ in Proc. 12th South East Asian Tech. Univ.Consortium (SEATUC), vol. 1, Mar. 2018, pp. 1–5. [9] Index Mundi USA. Accessed: Feb. 5, 2022. [Online]. Available: https://www.indexmundi.com/agriculture/?country=pk&commodity=cotton& graph=yield [10] S. M. Rahman and G. Ravi, ‘‘Role of artificial intelligence in pest management,’’Current Topics Agricult. Sci., vol. 7, pp. 64–81, Jan. 2022. [11] I. Saher, A. Khan, M. Z. Jhandir, R. Kazmi, and I. S. Bajwa, ‘‘Analyzing app releasing and the updating behavior of Android apps developers,’’Pakistan J. Eng. Technol., vol. 4, pp. 106–111, Jan. 2021 [12] B. Ramzan, I. Bajwa, R. Kazmi, and S. Ramzan, ‘‘An intelligent data analytics based model driven recommendation system,’’ J. Universal Comput.Sci., vol. 25, p. 1353, Feb. 2019 [13] A. Hussain, K. Lakshminarayanan, R. Dhanker, S. Shastri, and M. B. Desai, ‘‘Analysis and prediction of crop infestation using machine learning,’’ in Sustainable Advanced Computing. Cham, Switzerland:Springer, 2022, pp. 15–26 [14] D. Marković, D. Vujičić, S. Tanasković, B. Dordevic, S. Randić, and Z.Stamenković, ‘‘Prediction of pest insect appearance using sensors and machine learning,’’ Sensors, vol. 21, no. 14, p. 4846, Jul. 2021 [15] M. S. Latif, R. Kazmi, N. Khan, R. Majeed, S. Ikram, and M. M. Ali-Shahid, ‘‘Pest prediction in rice using IoT and feed forward neural network,’’ KSII Trans. Internet Inf. Syst., vol. 16, pp. 133–152, Jan. 2022 [16] O. Nanushi, V. Sitokonstantinou, I. Tsoumas, and C. Kontoes, ‘‘Pest presence prediction using interpretable machine learning,’’ 2022, arXiv:2205.07723 [17] O. Nanushi, V. Sitokonstantinou, I. Tsoumas, and C. Kontoes, ‘‘Pest presence prediction using interpretable machine learning,’’ 2022, arXiv:2205.07723 [18] T. Ojha, S. Misra, and N. S. Raghuwanshi, ‘‘Sensing-cloud: Leveraging the benefits for agricultural applications,’’ Comput. Electron. Agricult.,vol. 135, pp. 96–107, 2017 [19] C. Changqing, L. Hui, and H.Wenjun, ‘‘Internet of Agriculture-based low cost smart greenhouse remote monitor system,’’ in Proc. Chin. Autom.Congr. (CAC), 2018, pp. 3940–3945 [20] D. Gao, Q. Sun, B. Hu, and S. Zhang, ‘‘A framework for agricultural pest and disease monitoring based on Internet-of-Things and unmanned aerial vehicles,’’ Sensors, vol. 20, no. 5, p. 1487, Mar. 2020 [21] M. Dai, M. M. H. Dorjoy, H. Miao, and S. Zhang, ‘‘A new pest detection method based on improved YOLOv5m,’’ Insects, vol. 14, no. 1, p. 54,Jan. 2023 [22] A new mobile application of agricultural pests recognition using deep learning in cloud computing system, Mohamed Esmail Karar , Fahad Alsunaydi , Sultan Albusaymi , Sultan Alotaibi, Alexandria Engineering Journal,Volume 60 , Issue 5, October 2021, Pages 4423-4432, https://doi.org/10.1016/j.aej.2021.03.009 [23] T. Ojha, S. Misra, and N. S. Raghuwanshi, ‘‘Wireless sensor networks for agriculture: The state-of-the-art in practice and future challenges,’’ Comput.Electron. Agricult., vol. 118, pp. 66–84,Oct. 2015 https://www.sciencedirect.com/journal/alexandria-engineering-journal https://www.sciencedirect.com/journal/alexandria-engineering-journal https://www.sciencedirect.com/journal/alexandria-engineering-journal/vol/60/issue/5 https://doi.org/10.1016/j.aej.2021.03.009