DECISION SUPPORT SYSTEM FOR CROP CULTIVATION MSC IN IT Machine Learning and Data Science for Decision Making in Crop Cultivation S.P.T.P. Senadheera 189472R Faculty of Information Technology University of Moratuwa Sri Lanka August 2021 Msc in IT, Faculty of IT, University of Moratuwa i Declaration I the undersigned solemnly declare that the project report “Machine Learning and Data Science for Decision Making in Crop Cultivation” is based on my own work carried out during the course of my study under the supervision of Mrs. Indika Karunarathne I. I assert the statements made and conclusions drawn are an outcome of my research work. I further certify that II. The work contained in the report is original and has been done by me under the general supervision of my supervisor. III. The work has not been submitted to any other Institution for any other degree/diploma/certificate in this university or any other University of India or abroad. IV. We have followed the guidelines provided by the university in writing the report. V. Whenever we have used materials (data, theoretical analysis, and text) from other sources, we have given due credit to them in the text of the report and giving their details in the references. S.P.T.P. Senadheera Student Name Date Student Signature Supervised by Mrs. Indika Karunarathne Supervisor Name Supervisor Signature Date ii Acknowledgement This project would not have been possible without the support of many people. Many thanks to my adviser, Mrs. Indika Karunarathne, who read my numerous revisions and helped to make some sense of the confusion. Also thanks to the authorities of Department of Agriculture, Sabaragamuwa Province, who offered relevant details and support. Thanks to the University of Moratuwa, Faculty on Information Technology for awarding me a Dissertation Completion Fellowship to complete this project. And finally, thanks to parents, and numerous friends who endured this long process with me, always offering support and love. iii Table of Contents Declaration ....................................................................................................................................... i Acknowledgement .......................................................................................................................... ii Abstract ........................................................................................................................................... 1 List of Figures ................................................................................................................................. 2 List of Tables .................................................................................................................................. 3 1. Introduction ............................................................................................................................. 4 2. Background and Motivation .................................................................................................... 6 3. Aim and Objectives ............................................................................................................... 13 Aim ............................................................................................................................................ 13 Objectives .................................................................................................................................. 13 4. Methodology .......................................................................................................................... 14 Building Price Model ................................................................................................................ 14 Data Integration ..................................................................................................................... 14 Prediction Based on the Model ................................................................................................. 18 Price Model Prediction Results ............................................................................................. 19 ............................................................................................................................................... 19 Production Prediction Model .................................................................................................... 21 Data Integration ..................................................................................................................... 21 Prediction Based on Model ....................................................................................................... 26 Production Model Prediction Results .................................................................................... 28 Evaluation of Simple and Multiple Linear Regression Models to do the predictions .............. 30 More on Simple Linear Regression Model............................................................................ 31 Performing the Linear Regression ......................................................................................... 31 More on Multiple Linear Regression Model ......................................................................... 32 Performing Multiple Linear Regression ................................................................................ 33 5. Technical Implementation ..................................................................................................... 34 More on Technical Implications ............................................................................................... 36 Kivy ....................................................................................................................................... 36 More on Pandas ..................................................................................................................... 36 Pandas Library Features ........................................................................................................ 37 iv More on Panadas Datareader ................................................................................................. 37 More on XAMPP Local Server ............................................................................................. 38 ....................................................................................................................................................... 38 Weather API .......................................................................................................................... 39 Source Codes to Manipulate Weather Information fetched from Openweathermap API .......................................................................................... Error! Bookmark not defined. ............................................................................................................................................... 42 6. Future Developments and Benefits of the Application ......................................................... 44 Introduction ............................................................................................................................... 44 Characteristics of a Crop Prediction Decision Support System ................................................ 44 Benefits of DSS in Crop Prediction .......................................................................................... 44 7. Results and Discussion .......................................................................................................... 46 8. Future Development .............................................................................................................. 48 9. References ............................................................................................................................. 50 DECISION SUPPORT SYSTEM FOR CROP CULTIVATION 1 Abstract In many situations, farmers face lots of difficulties due to not gaining enough income for their harvest as a result of it, considerable amount of harvest is wasted because of not having enough return on investment. Although government introduced many approaches, they seem to have been unable to address the issues of crop prediction and sustainable agriculture as farmers complain that the policies created by the authorities never match with the expectations of farmers’ community. Considerable amount of population still engage in agricultural sector. Therefore, their contribution to the GDP has been representing an important portion through last few decades. Therefore this research has been conducted to support farmers to make optimum decisions based on various factors such as weather, price, and potential production to make cultivations. The research is based on two basic data mining models (Price and Expected Production) to predict the price and Production for a selected crop based on a particular district. The prediction outcome is presented using a mobile application with user friendly interfaces. Price model is based on the production (MT), per capita consumption, imports and inflation with the accuracy of 77.93% and the Production model is based on the climatic conditions such as humidity, wind speed, sun hours, rainfalls and temperature with the accuracy of 65.08%. The production model is to be further developed by adding the feature of soil moisture as it is an important factor to decide which crop is to be cultivated. Furthermore, an additional model is to be added to predict the amount of fertilizer to be added based to get the optimum yield. Keywords:-crop, price, production, model, prediction, yield, fertilizer, moisture, accuracy 2 List of Figures Figure 1 Crop Production in Sri Lanka ........................................................................................... 7 Figure 2 Daily Price Fluctuation of Selected Crops (CBSL-Daily Price Report-2021) ................. 7 Figure 3 Crop Wastage Amount on Media ..................................................................................... 8 Figure 4 Price and Suggested Amount of Hectare 1 ....................................................................... 9 Figure 5 Price and Suggested Amount of Hectare 2 ....................................................................... 9 Figure 6 Price and Suggested Amount of Hectare 2 ..................................................................... 10 Figure 7 Hourly Weather Forecast ................................................................................................ 11 Figure 8 Hourly Weather Forecast- Nuwara Eliya District .......................................................... 12 Figure 9 Monthly Inflation............................................................................................................ 14 Figure 10 Random Realistic Number Generation ......................................................................... 15 Figure 11 Helgi Library Website is a reliable source to get consumption details ........................ 16 Figure 12 Inflation Statistics from World Bank Data ................................................................... 16 Figure 13 Imports Statistics .......................................................................................................... 17 Figure 14 Created Data Model ...................................................................................................... 17 Figure 15 Independent Variables of the model ............................................................................. 18 Figure 16 Python Code to build and predict the model ................................................................ 18 Figure 17 Displaying the contents of the CSV file ....................................................................... 19 Figure 18 Price Information is the dependent variable which predicted based on the inputs shown in above figure ........................................................................................................ 20 Figure 19 Accuracy of the model .................................................................................................. 20 Figure 20 Home Page of the website from which the weather information has been extracted. ....................................................................................................................................... 21 Figure 21 District, City and Regional wise weather information has been extracted from this Interface.................................................................................................................................. 22 Figure 22 Average Rain falls ........................................................................................................ 22 Figure 23 Average Rail Falls ........................................................................................................ 23 Figure 24 Average Wind Speed .................................................................................................... 23 Figure 25 Average Sun Hours ....................................................................................................... 24 Figure 26 Average Humidity ........................................................................................................ 24 Figure 27 Random Realisric Number Generation ........................................................................ 25 Figure 28 District Wise Annual Crop Production Information .................................................... 25 Figure 29 The Production Model .................................................................................................. 26 Figure 30 Training, Predicting and evaluating the model............................................................. 27 Figure 31 Importing Pandas Library and other Packages for Data Mining .................................. 27 Figure 32 Importing Production Model Dataset to Python ........................................................... 28 Figure 33 Splitting the Model into Independent and Dependent variables .................................. 28 Figure 34 Evaluation results of the production model .................................................................. 29 Figure 35 Sample Image of a Linear Regression Model ............................................................. 30 Figure 36 Simple Linear Equation ................................................................................................ 31 3 Figure 37 Multiple Linear Equation ............................................................................................. 33 Figure 38 Kivy Logo ..................................................................................................................... 36 Figure 39 Pandas Logo ................................................................................................................. 36 Figure 40 Pandas Datareader Logo ............................................................................................... 37 Figure 41 Installing Panadas Datareader in system environment ................................................. 38 Figure 42 Importing Pandas Datareader to the python environment ............................................ 38 Figure 43 Fetching inflation rate from worldbank datasource...................................................... 38 Figure 44 Xampp Environment .................................................................................................... 38 Figure 45 Information of the registered farmers have been stored in local server ....................... 39 Figure 46 Services of openweathermap API ................................................................................ 39 Figure 47 Services of openweathermap API ................................................................................ 40 Figure 48 Accessing Weather Information Based on the API key Passed for the url .................. 41 Figure 49 Source Code to Store Weather data fetched from API ................................................. 41 Figure 50 Source Code to Manipulated Weather data fetched from the API ............................... 41 Figure 51 Predicting the Production based on Weather data fetched from the API ..................... 42 Figure 52 Login Window .............................................................................................................. 42 Figure 53 Home Interface ............................................................................................................. 42 Figure 54 Window to Show Price fluctuation for last 2 weeks .................................................... 43 Figure 55 Window for Price and Production Prediction ............................................................... 43 Figure 56 Actual Price Vs the Predicted Price .............................................................................. 46 List of Tables Table 1 Daily Price Report-CBSL-2019 ......................................................................................... 4 Table 2 Expected Price Levels and % Hectares ............................................................................ 10