├── 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 |  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 | -------------------------------------------------------------------------------- /imgs/flowers.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /imgs/input.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 49 | -------------------------------------------------------------------------------- /imgs/model.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /imgs/plant.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /imgs/weather.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 72 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 |