├── CYP.png ├── Final_Data.csv ├── README.md ├── RF_Model ├── RF_model_Py3 ├── RF_predict.py ├── __pycache__ └── pytest.cpython-36.pyc ├── imgs ├── bg_svg.svg ├── flowers.svg ├── input.svg ├── model.svg ├── plant.svg └── weather.svg ├── index.php ├── input_lists.txt ├── predict.php ├── requirements.txt └── style.css /CYP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VaibhavSaini19/Crop-Yield-Prediction-using-ML/c34a4db2763cc016fb1f378d0e0683103170a067/CYP.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Crop-Yield-Prediction-using-ML 2 | 3 | A simple Web application developed in order to provide the farmers/users an approximation on how much amount of crop yield will be produced depending upon the given input. 4 | The application uses a Random Forest Machine Learning model, which was trained on over 20 years of data from 30 districts of Maharashtra, along with automatic live weather fetching for prediction. The model achieved 5 | an accuracy of around 86% and can be even further improved with more data. 6 | 7 | ## Usage 8 | - Make sure you have WAMP / XAMPP installed on your machine 9 | - Clone the repo 10 | - Ensure Apache server is running 11 | - Run index.php through localhost 12 | - Select the `district`, `Crop`, `Soil` and enter the `Area` 13 | - Click on `Predict` 14 | - Wait for a few seconds 15 | - The results will appear below the predict button 16 | 17 | ```Web link will be available soon...untill then``` 18 | Check out the preview 19 | 20 | ## Preview 21 | ![](https://github.com/VaibhavSaini19/Crop-Yield-Prediction-using-ML/blob/master/CYP.png) 22 | -------------------------------------------------------------------------------- /RF_Model: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VaibhavSaini19/Crop-Yield-Prediction-using-ML/c34a4db2763cc016fb1f378d0e0683103170a067/RF_Model -------------------------------------------------------------------------------- /RF_model_Py3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VaibhavSaini19/Crop-Yield-Prediction-using-ML/c34a4db2763cc016fb1f378d0e0683103170a067/RF_model_Py3 -------------------------------------------------------------------------------- /RF_predict.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pandas as pd 3 | import datetime 4 | from bs4 import BeautifulSoup 5 | import pickle 6 | import requests, json 7 | 8 | # print ('Number of arguments:', len(sys.argv), 'arguments.') 9 | # print ('Argument List:', str(sys.argv)) 10 | 11 | with open('RF_Model', 'rb') as f: 12 | RanFor = pickle.load(f) 13 | 14 | 15 | dist_list = ['AHMEDNAGAR', 'AKOLA', 'AMRAVATI', 'AURANGABAD', 'BEED', 'BHANDARA', 'BULDHANA', 'CHANDRAPUR', 'DHULE', 'GADCHIROLI', 'GONDIA', 'HINGOLI', 'JALGAON', 'JALNA', 'KOLHAPUR', 'LATUR', 'NAGPUR', 'NANDED', 'NANDED', 'NASHIK', 'OSMANABAD', 'PARBHANI', 'PUNE', 'SANGLI', 'SATARA', 'SATARA', 'THANE', 'WARDHA', 'WASHIM', 'YAVATMAL'] 16 | crop_list = ['Jowar', 'Bajra', 'Wheat'] 17 | soil_list = ['chalky', 'clay', 'loamy', 'sandy', 'silty'] 18 | 19 | district = sys.argv[1] 20 | Crop = sys.argv[2] 21 | Area = int(sys.argv[3]) 22 | soil_type = sys.argv[4] 23 | 24 | # district = 'PUNE' 25 | # Crop = 'Jowar' 26 | # Area = 598400 27 | # soil_type = 'clay' 28 | 29 | district = "District:_"+district 30 | Crop = "Crop:_"+Crop 31 | soil_type = "Soil_type:_"+soil_type 32 | 33 | 34 | 35 | 36 | api_key = "YOUR_API_KEY" # Use your own API key. You can get it for free from openweathermap 37 | 38 | base_url = "http://api.openweathermap.org/data/2.5/weather?" 39 | 40 | # city_name = sys.argc[1] 41 | city_name = 'PUNE' 42 | 43 | complete_url = base_url + "appid=" + api_key + "&q=" + city_name 44 | 45 | response = requests.get(complete_url) 46 | 47 | x = response.json() 48 | 49 | # print(x) 50 | if x["cod"] != "404": 51 | y = x["main"] 52 | temp = y["temp"]-273 53 | humi = y["humidity"] 54 | try: 55 | preci_humi_link = 'https://www.worldweatheronline.com/lang/en-in/pune-weather/maharashtra/in.aspx' 56 | p2 = requests.get(preci_humi_link) 57 | s2 = BeautifulSoup(p2.content, 'html.parser') 58 | preci_table = ((s2.find_all('div', attrs={'class':'tb_cont_item', 'style':'background-color:#ffffff;'}))) 59 | preci = 0 60 | for ele in preci_table[21::2]: 61 | if ele.text == '0.00 mm': 62 | preci += float(ele.text.replace("mm", "").strip()) 63 | preci *= 6 64 | # print("Average precipitation: ", preci) 65 | humi_table = ((s2.find_all('div', attrs={'class':'tb_row tb_rain'}))) 66 | humi = 0 67 | for ele in humi_table: 68 | if len(ele.text) > 15: 69 | humi = ele.text.replace("Rain", "").split("%")[:-1] 70 | humi = sum(list(map(float, humi))) 71 | humi *= 6 72 | # print ("Average humidity: ", humi) 73 | except: 74 | preci = 0 75 | humi = 0 76 | 77 | 78 | X = ['Area', 'Temperature', 'Precipitaion', 'Humidity', 'Soil_type:_chalky', 79 | 'Soil_type:_clay', 'Soil_type:_loamy', 'Soil_type:_peaty', 80 | 'Soil_type:_sandy', 'Soil_type:_silt', 81 | 'District:_AHMEDNAGAR', 'District:_AKOLA', 'District:_AMRAVATI', 82 | 'District:_AURANGABAD', 'District:_BEED', 'District:_BHANDARA', 83 | 'District:_BULDHANA', 'District:_CHANDRAPUR', 'District:_DHULE', 84 | 'District:_GADCHIROLI', 'District:_GONDIA', 'District:_HINGOLI', 85 | 'District:_JALGAON', 'District:_JALNA', 'District:_KOLHAPUR', 86 | 'District:_LATUR', 'District:_NAGPUR', 'District:_NANDED', 87 | 'District:_NANDURBAR', 'District:_NASHIK', 'District:_OSMANABAD', 88 | 'District:_PARBHANI', 'District:_PUNE', 'District:_SANGLI', 89 | 'District:_SATARA', 'District:_SOLAPUR', 'District:_THANE', 90 | 'District:_WARDHA', 'District:_WASHIM', 'District:_YAVATMAL', 91 | 'Crop:_Bajra', 'Crop:_Jowar', 'Crop:_Wheat', 'Season:_Kharif', 92 | 'Season:_Rabi', 'Season:_Rabi '] 93 | 94 | index_dict = dict(zip(X,range(len(X)))) 95 | 96 | vect = {} 97 | for key, val in index_dict.items(): 98 | vect[key] = 0 99 | try: 100 | vect[district] = 1 101 | except Exception as e: 102 | print("Exception occered for DISTRICT!", e) 103 | try: 104 | vect[Crop] = 1 105 | except Exception as e: 106 | print("Exception occered for CROP!") 107 | try: 108 | vect[soil_type] = 1 109 | except Exception as e: 110 | print("Exception occered for SOIL TYPE!") 111 | try: 112 | vect['Area'] = Area 113 | except Exception as e: 114 | print("Exception occered for AREA!", e) 115 | try: 116 | vect['Temperature'] = temp 117 | except Exception as e: 118 | print("Exception occered for TEMP!", e) 119 | try: 120 | vect['Precipitaion'] = preci 121 | except Exception as e: 122 | print("Exception occered for PRECI!", e) 123 | try: 124 | vect['Humidity'] = humi 125 | except Exception as e: 126 | print("Exception occered for HUMI!", e) 127 | 128 | now = datetime.datetime.today() 129 | season = "Season:_Kharif" if (now.month >= 7 and now.month <= 10) else "Season:_Rabi" 130 | vect[season] = 1 131 | 132 | # print(vect, len(vect)) 133 | df = pd.DataFrame.from_records(vect, index=[0]) 134 | 135 | crop_yield = RanFor.predict(df)[0] 136 | print ("The predicted YIELD for given attributes is approximately: ", (crop_yield), "tons.") 137 | 138 | 139 | else: 140 | print(" District Not Found ") 141 | -------------------------------------------------------------------------------- /__pycache__/pytest.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VaibhavSaini19/Crop-Yield-Prediction-using-ML/c34a4db2763cc016fb1f378d0e0683103170a067/__pycache__/pytest.cpython-36.pyc -------------------------------------------------------------------------------- /imgs/bg_svg.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /imgs/flowers.svg: -------------------------------------------------------------------------------- 1 | flowers -------------------------------------------------------------------------------- /imgs/input.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 10 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /imgs/model.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /imgs/plant.svg: -------------------------------------------------------------------------------- 1 | environment1 -------------------------------------------------------------------------------- /imgs/weather.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 9 | 12 | 14 | 15 | 17 | 19 | 20 | 21 | 22 | 24 | 26 | 29 | 32 | 33 | 34 | 37 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Crop Yield Prediction 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
31 |
32 |
33 |
34 |
Crop Yield Prediction
35 |
using Machine Learning
36 |
37 |
38 |
39 |  Developed by: 40 |
41 |
    42 |
  • Sachin Sahil
  • 43 |
  • Shubham Katte
  • 44 |
  • Vaibhav Saini
  • 45 |
46 |
47 | 52 | 53 |
54 |
55 | 56 | 57 |
58 |
59 |
60 |
61 |
62 |
63 | 64 |
65 |
Enter details
66 |
Provide information for the crop like its type, the area of the farm, the soil category and the district in which it is to be grown
67 |
68 |
69 |
70 | 71 |
72 |
Live weather Fetch
73 |
Current weather details like the temperature, humidity, and precipitaion are fetched automatically from the internet to be used for prediction
74 |
75 |
76 |
77 | 78 |
79 |
Prediction
80 |
A Random Forest ML model, trained on past 20 years of data, is used to predict the approximate crop yield
81 |
82 |
83 |
84 |
85 |
86 | 87 |
88 |
89 |
90 |

Crop Yield Predictor

91 |
92 |
93 |
94 | 95 | 96 |
97 |
98 | 99 | 100 |
101 |
102 | 103 | 104 |
105 |
106 | 107 | 108 |
109 |
110 | 111 |
112 |
113 | 115 |
116 |
117 | 118 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /input_lists.txt: -------------------------------------------------------------------------------- 1 | { 2 | "districts" : [ 3 | "AHMEDNAGAR", "AKOLA", "AMRAVATI", "AURANGABAD", "BEED", "BHANDARA", "BULDHANA", "CHANDRAPUR", "DHULE", "GADCHIROLI", 4 | "GONDIA", "HINGOLI", "JALGAON", "JALNA", "KOLHAPUR", "LATUR", "NAGPUR", "NANDED", "NANDURBAR", "NASHIK", 5 | "OSMANABAD", "PARBHANI", "PUNE", "SANGLI", "SATARA", "SOLAPUR", "THANE", "WARDHA", "WASHIM", "YAVATMAL" 6 | ], 7 | 8 | "crops" : [ 9 | "Jowar", "Bajra", "Wheat" 10 | ], 11 | 12 | "soils" : [ 13 | "chalky", "clay", "loamy", "sandy", "silty" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /predict.php: -------------------------------------------------------------------------------- 1 | &1", $output, $error); 10 | $res = shell_exec("python3 RF_predict.py $district $crop $area $soil 2>&1"); 11 | 12 | echo $res; 13 | // var_dump($output); 14 | // var_dump($error); 15 | // var_dump($res); 16 | 17 | 18 | ?> -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VaibhavSaini19/Crop-Yield-Prediction-using-ML/c34a4db2763cc016fb1f378d0e0683103170a067/requirements.txt -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | html { 2 | scroll-behavior: smooth; 3 | } 4 | body { 5 | padding: 0; 6 | margin: 0; 7 | display: flex; 8 | flex-direction: column; 9 | } 10 | .svgs { 11 | position: fixed; 12 | } 13 | .page { 14 | width: 100%; 15 | height: 100vh; 16 | position: relative; 17 | } 18 | 19 | .scrollIndicator{ 20 | position: absolute; 21 | bottom: 12px; 22 | height: 0; 23 | width: 0; 24 | border-left: 25px solid transparent; 25 | border-right: 25px solid transparent; 26 | border-top: 25px solid #f00; 27 | animation: down 1.5s ease-in-out infinite; 28 | } 29 | @keyframes down{ 30 | 0%{ transform: translateY(0);} 31 | 50%{ transform: translateY(100%);} 32 | 100%{ transform: translateY(0);} 33 | } 34 | 35 | #part1 { 36 | display: flex; 37 | flex-direction: row; 38 | justify-content: space-around; 39 | align-items: center; 40 | } 41 | #part1 .title { 42 | font-size: 3em; 43 | font-weight: bold; 44 | letter-spacing: 2px; 45 | } 46 | #part1 .title-support { 47 | font-size: 1.4em; 48 | } 49 | #part1 .imgContainer { 50 | width: 30em; 51 | height: 30em; 52 | } 53 | #part1 .imgContainer img { 54 | width: 100%; 55 | } 56 | #part1 .info .dev { 57 | margin-top: 4em; 58 | margin-bottom: 4em; 59 | font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS", sans-serif; 60 | } 61 | #part1 .info .btn-grp .try { 62 | display: inline-block; 63 | text-decoration: none; 64 | color: white; 65 | font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande", "Lucida Sans Unicode", Geneva, Verdana, 66 | sans-serif; 67 | font-weight: bold; 68 | padding: 0.6em 2em; 69 | margin-right: 2em; 70 | font-size: 1.4em; 71 | border: none; 72 | border-radius: 40px; 73 | background-image: linear-gradient(to right, #1cd8d2, #93edc7); 74 | box-shadow: 4px 4px 10px #81ecec; 75 | transition: 0.3s; 76 | } 77 | #part1 .info .btn-grp .try:hover { 78 | cursor: pointer; 79 | transform: scale(1.05); 80 | } 81 | #part1 .info .btn-grp .more { 82 | font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande", "Lucida Sans Unicode", Geneva, Verdana, 83 | sans-serif; 84 | padding: 0.6em 2em; 85 | font-size: 1.2em; 86 | border: 1px solid gray; 87 | background-color: transparent; 88 | border-radius: 40px; 89 | transition: 0.3s; 90 | } 91 | #part1 .info .btn-grp .more:hover { 92 | cursor: pointer; 93 | transform: scale(1.05); 94 | } 95 | 96 | #part2 { 97 | display: flex; 98 | flex-direction: row; 99 | justify-content: center; 100 | align-items: center; 101 | } 102 | .text-blue { 103 | color: #5e72e4; 104 | } 105 | .text-green { 106 | color: #2dce89; 107 | } 108 | .text-orange { 109 | color: #fb6340; 110 | } 111 | #part2 .myCard { 112 | display: flex; 113 | flex-direction: column; 114 | border-radius: 10px; 115 | width: 20em; 116 | margin: 3em; 117 | min-height: 18em; 118 | padding: 1em; 119 | border: none; 120 | filter: drop-shadow(4px 4px 15px rgba(0, 0, 0, 0.15)); 121 | transition: 0.25s; 122 | } 123 | #part2 .myCard:hover { 124 | transform: translateY(-10%); 125 | } 126 | #part2 .myCard .myCard-img { 127 | width: 4em; 128 | } 129 | #part2 .myCard .myCard-img img { 130 | width: 100%; 131 | } 132 | #part2 .myCard .myCard-title { 133 | font-size: 1.5em; 134 | font-weight: bold; 135 | margin-top: 0.8em; 136 | margin-bottom: 0.8em; 137 | } 138 | #part2 .myCard .myCard-body { 139 | opacity: 0.75; 140 | } 141 | 142 | #part3 { 143 | display: flex; 144 | flex-direction: row; 145 | align-items: center; 146 | } 147 | #part3 .imgContainer { 148 | width: 20em; 149 | } 150 | #part3 .imgContainer img { 151 | width: 100%; 152 | } 153 | --------------------------------------------------------------------------------