-
Notifications
You must be signed in to change notification settings - Fork 1
/
agripredictorclsify.py
370 lines (307 loc) · 15.3 KB
/
agripredictorclsify.py
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
34
35
36
37
38
39
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
import os
from twilio.rest import Client
account_sid = "AC74c65f66f1de79c6a6b4f9314f161135"
auth_token = "04ca45f4d51b1c9e6dff55d9b786e3e8"
client = Client(account_sid, auth_token)
dataset = pd.read_csv('C:\\Users\\Antik\\Desktop\\Tech-Master-5-master\\FinalFinal.csv')
#print(dataset.shape)
data2 = dataset[['msp','climate_conditions','rainfall','nitrogen','Season','soil_conditions']]
datalabels = dataset[['Type']]
dataset2 = pd.get_dummies(data2)
print(dataset2.iloc[:,:].head(5))
print(data2.head())
print(dataset2.shape)
pbset = pd.read_csv("C:\\Users\\Antik\\Desktop\\Tech-Master-5-master\\Finalpunjab.csv")
pb2 = pbset[['msp','climate_conditions','rainfall','nitrogen','Season','soil_conditions']]
pblabels = dataset[['Type']]
pbset2 = pd.get_dummies(pb2)
tmset = pd.read_csv("C:\\Users\\Antik\\Desktop\\Tech-Master-5-master\\Finaltamil.csv")
tm2 = tmset[['msp','climate_conditions','rainfall','nitrogen','Season','soil_conditions']]
tmlabels = dataset[['Type']]
tmset2 = pd.get_dummies(pb2)
print ("Enter 1 for Punjab and 2 for Tamil Nadu")
state = int(input("Enter the choice: "))
if (state == 1):
X = pbset2.iloc[:,0:13].values
Y = pblabels.iloc[:,:].values
pb = pd.read_csv("C:\\Users\\Antik\\Desktop\\Tech-Master-5-master\\Finalpunjab.csv")
X_train,X_test,Y_train,Y_test= train_test_split(X,Y,test_size=0)
clf = RandomForestClassifier(n_estimators=100)
clf.fit(X_train,Y_train)
climate = int(input("Enter the average temperature in celcius: "))
print ("Enter the soil type: ")
print ("0 for Alluvial soil: ")
print ("1 for Black soil: ")
print ("2 for Laterite soil: ")
print ("3 for Marshy soil: ")
print ("4 for Red soil: ")
soiltype = int(input(('Enter your option: ') ))
rainfall = int(input("Enter the rainfall in mm in your region: "))
nitrogen_nutri = int(input("Enter the nitrogen content in kg/ha: "))
print("Enter the season: ")
print("0 for kharif: ")
print("1 for rabi: ")
print("2 for year long: ")
season = int(input("Enter your choice: "))
if (season==0):
if(soiltype==0):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,1,0,1,0,0,0,0,1]]))
elif(soiltype==1):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,1,0,0,1,0,0,0,1]]))
elif(soiltype==2):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,1,0,0,0,1,0,0,1]]))
elif(soiltype==3):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,1,0,0,0,0,1,0,1]]))
elif(soiltype==4):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,1,0,0,0,0,0,1,1]]))
else:
if(soiltype==0):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,0,1,1,0,0,0,0,0]]))
elif(soiltype==1):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,0,1,0,1,0,0,0,0]]))
elif(soiltype==2):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,0,1,0,0,1,0,0,0]]))
elif(soiltype==3):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,0,1,0,0,0,1,0,0]]))
elif(soiltype==4):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,0,1,0,0,0,0,1,0]]))
name = dataset['crop']
if (name[crp[0]] == 'maize'):
a = "According to your input the best crop to harvest would be maize or potatoes or tomatoes"
print (a)
elif (name[crp[0]] == 'cotton'):
a = "According to your input the best crop to harvest would be cotton or sugarcane or jute"
print (a)
elif (name[crp[0]] == 'wheat'):
a = "According to your input the best crop to harvest would be wheat or cotton"
print (a)
elif (name[crp[0]] == 'paddy'):
a = "According to your input the best crop to harvest would be paddy or sugarcane or millet or groundnut or ragi"
print (a)
elif (name[crp[0]] == 'barley'):
a = "According to your input the best crop to harvest would be barley or potato"
print(a)
elif (name[crp[0]] == 'finger millet'):
a = "According to your input the best crop to harvest would be finger millet or ground nut or ragi"
print (a)
elif (name[crp[0]] == 'green gram'):
a = "According to your input the best crop to harvest would be green gram or millet"
print (a)
elif (name[crp[0]] == 'tea'):
a = "According to your input the best crop to harvest would be tea"
print (a)
elif (name[crp[0]] == 'chillies'):
a = "According to your input the best crop to harvest would be chillies or rice or wheat or sugarcane"
print (a)
elif (name[crp[0]] == 'turmeric'):
a = "According to your input the best crop to harvest would be turmeric"
print (a)
elif (name[crp[0]] == 'sugar cane'):
a = "According to your input the best crop to harvest would be sugar cane or wheat or cotton or jute "
print (a)
elif (name[crp[0]] == 'jute'):
a = "According to your input the best crop to harvest would be jute or wheat or cotton "
print (a)
elif (name[crp[0]] == 'sorghum'):
a = "According to your input the best crop to harvest would be sorghum or cotton or pearl millet "
print (a)
elif (name[crp[0]] == 'bajra'):
a = "According to your input the best crop to harvest would be bajra or wheat or sugarcane "
print (a)
elif (name[crp[0]] == 'red gram'):
a = "According to your input the best crop to harvest would be red gram or Bengal gram "
print (a)
elif (name[crp[0]] == 'black gram'):
a = "According to your input the best crop to harvest would be black gram or red gram or bengal gram "
print (a)
elif (name[crp[0]] == 'sesame'):
a = "According to your input the best crop to harvest would be sesame or sunflower or soyabeans "
print (a)
elif (name[crp[0]] == 'sweet potato'):
a = "According to your input the best crop to harvest would be sweet potato or beans or peas "
print (a)
elif (name[crp[0]] == 'mustard'):
a = "According to your input the best crop to harvest would be mustard or wheat or barley "
print (a)
elif (name[crp[0]] == 'soyabean'):
a = "According to your input the best crop to harvest would be soyabean or sunflower or sesame "
print (a)
elif (name[crp[0]] == 'lin seed'):
a = "According to your input the best crop to harvest would be lin seed or wheat or rice"
print (a)
elif (name[crp[0]] == 'niger'):
a = "According to your input the best crop to harvest would be niger "
print (a)
elif (name[crp[0]] == 'capsicum'):
a = "According to your input the best crop to harvest would be capsicum "
print (a)
elif (name[crp[0]] == 'cucumber'):
a = "According to your input the best crop to harvest would be cucumber "
print (a)
elif (name[crp[0]] == 'ridge gourd'):
a = "According to your input the best crop to harvest would be ridge gourd "
print (a)
elif (name[crp[0]] == 'bottle gourd'):
a = "According to your input the best crop to harvest would be bottle gourd "
print (a)
elif (name[crp[0]] == 'snake gourd'):
a = "According to your input the best crop to harvest would be snake gourd "
print (a)
elif (name[crp[0]] == 'Water melon'):
a = "According to your input the best crop to harvest would be Water melon "
print (a)
elif (name[crp[0]] == 'muskmelon'):
a = "According to your input the best crop to harvest would be muskmelon "
print (a)
elif (name[crp[0]] == 'cauli flower'):
a = "According to your input the best crop to harvest would be cauli flower"
print (a)
print ("According to your input the best crop to harvest would be: ", name[crp[0]])
else:
X_1 = pbset2.iloc[:,0:13].values
Y_1 = pblabels.iloc[:,:].values
tm = pd.read_csv("C:\\Users\\Antik\\Desktop\\Tech-Master-5-master\\Finaltamil.csv")
X_train_1,X_test_1,Y_train_1,Y_test_1= train_test_split(X_1,Y_1,test_size=0)
clf = RandomForestClassifier(n_estimators=100)
clf.fit(X_train_1,Y_train_1)
climate = int(input("Enter the average temperature in celcius: "))
print ("Enter the soil type: ")
print ("0 for Alluvial soil: ")
print ("1 for Black soil: ")
print ("2 for Laterite soil: ")
print ("3 for Marshy soil: ")
print ("4 for Red soil: ")
soiltype = int(input(('Enter your option: ') ))
rainfall = int(input("Enter the rainfall in mm in your region: "))
nitrogen_nutri = int(input("Enter the nitrogen content in kg/ha: "))
print("Enter the season: ")
print("0 for kharif: ")
print("1 for rabi: ")
print("2 for year long: ")
season = int(input("Enter your choice: "))
if (season==0):
if(soiltype==0):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,1,0,1,0,0,0,0,1]]))
elif(soiltype==1):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,1,0,0,1,0,0,0,1]]))
elif(soiltype==2):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,1,0,0,0,1,0,0,1]]))
elif(soiltype==3):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,1,0,0,0,0,1,0,1]]))
elif(soiltype==4):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,1,0,0,0,0,0,1,1]]))
else:
if(soiltype==0):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,0,1,1,0,0,0,0,0]]))
elif(soiltype==1):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,0,1,0,1,0,0,0,0]]))
elif(soiltype==2):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,0,1,0,0,1,0,0,0]]))
elif(soiltype==3):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,0,1,0,0,0,1,0,0]]))
elif(soiltype==4):
crp = (clf.predict([[climate,rainfall,nitrogen_nutri,0,1,0,0,0,0,1,0]]))
name = dataset['crop']
if (name[crp[0]] == 'maize'):
a = "According to your input the best crop to harvest would be maize or potatoes or tomatoes"
print (a)
elif (name[crp[0]] == 'cotton'):
a = "According to your input the best crop to harvest would be cotton or sugarcane or jute"
print (a)
elif (name[crp[0]] == 'wheat'):
a = "According to your input the best crop to harvest would be wheat or cotton"
print (a)
elif (name[crp[0]] == 'paddy'):
a = "According to your input the best crop to harvest would be paddy or sugarcane or millet or groundnut or ragi"
print (a)
elif (name[crp[0]] == 'barley'):
a = "According to your input the best crop to harvest would be barley or potato"
print(a)
elif (name[crp[0]] == 'finger millet'):
a = "According to your input the best crop to harvest would be finger millet or ground nut or ragi"
print (a)
elif (name[crp[0]] == 'green gram'):
a = "According to your input the best crop to harvest would be green gram or millet"
print (a)
elif (name[crp[0]] == 'tea'):
a = "According to your input the best crop to harvest would be tea"
print (a)
elif (name[crp[0]] == 'chillies'):
a = "According to your input the best crop to harvest would be chillies or rice or wheat or sugarcane"
print (a)
elif (name[crp[0]] == 'turmeric'):
a = "According to your input the best crop to harvest would be turmeric"
print (a)
elif (name[crp[0]] == 'sugar cane'):
a = "According to your input the best crop to harvest would be sugar cane or wheat or cotton or jute "
print (a)
elif (name[crp[0]] == 'jute'):
a = "According to your input the best crop to harvest would be jute or wheat or cotton "
print (a)
elif (name[crp[0]] == 'sorghum'):
a = "According to your input the best crop to harvest would be sorghum or cotton or pearl millet "
print (a)
elif (name[crp[0]] == 'bajra'):
a = "According to your input the best crop to harvest would be bajra or wheat or sugarcane "
print (a)
elif (name[crp[0]] == 'red gram'):
a = "According to your input the best crop to harvest would be red gram or Bengal gram "
print (a)
elif (name[crp[0]] == 'black gram'):
a = "According to your input the best crop to harvest would be black gram or red gram or bengal gram "
print (a)
elif (name[crp[0]] == 'sesame'):
a = "According to your input the best crop to harvest would be sesame or sunflower or soyabeans "
print (a)
elif (name[crp[0]] == 'sweet potato'):
a = "According to your input the best crop to harvest would be sweet potato or beans or peas "
print (a)
elif (name[crp[0]] == 'mustard'):
a = "According to your input the best crop to harvest would be mustard or wheat or barley "
print (a)
elif (name[crp[0]] == 'soyabean'):
a = "According to your input the best crop to harvest would be soyabean or sunflower or sesame "
print (a)
elif (name[crp[0]] == 'lin seed'):
a = "According to your input the best crop to harvest would be lin seed or wheat or rice"
print (a)
elif (name[crp[0]] == 'niger'):
a = "According to your input the best crop to harvest would be niger "
print (a)
elif (name[crp[0]] == 'capsicum'):
a = "According to your input the best crop to harvest would be capsicum "
print (a)
elif (name[crp[0]] == 'cucumber'):
a = "According to your input the best crop to harvest would be cucumber "
print (a)
elif (name[crp[0]] == 'ridge gourd'):
a = "According to your input the best crop to harvest would be ridge gourd "
print (a)
elif (name[crp[0]] == 'bottle gourd'):
a = "According to your input the best crop to harvest would be bottle gourd "
print (a)
elif (name[crp[0]] == 'snake gourd'):
a = "According to your input the best crop to harvest would be snake gourd "
print (a)
elif (name[crp[0]] == 'Water melon'):
a = "According to your input the best crop to harvest would be Water melon "
print (a)
elif (name[crp[0]] == 'muskmelon'):
a = "According to your input the best crop to harvest would be muskmelon "
print (a)
elif (name[crp[0]] == 'cauli flower'):
a = "According to your input the best crop to harvest would be cauli flower"
print (a)
print ("According to your input the best crop to harvest would be: ", name[crp[0]])
'''message = client.messages.create (
body=a,
from_ = "+14797633931",
to = "+919007488686"
)
print(message.sid)'''