Professional Documents
Culture Documents
Reference 1
Reference 1
2
values are appended to the final pandas DataFrame. The configuration for the set of rainfall values for the particular
missing values in the production attribute are filled randomly subdivision we use this configuration of ARIMA parameters
in the range [min, max] and appended to the newdf pandas to predict the rainfall till 2021.
DataFrame.
IV. METHODOLOGY
1. df=pd.read_csv("India_Rainfall.csv") As shown in figure 1 firstly when user opens the app in his
2. fin=pd.DataFrame() mobile it imports the location from Google. If the location is
3. p_values=range(0,5) detected user can enter the details about all parameters
4. d_values=range(0,5) required like soil type, temperature, rainfall. App runs the
5. q_values=range(0,5) algorithm and displays the list of crops suitable for entered
6. warnings.filterwarnings("ignore") data with predicted yield value. If location is not detected then
7. for sub in df.SUBDIVISION.unique(): user can enter location manually from drop down menu. App
8. df1=df.loc[df['SUBDIVISION']==sub] also shows the details and procedure to grow crops which you
9. series=pd.Series(df1.ANNUAL.tolist()) want.
10. cfg,error=evaluate_models(series.values,p_values,d_
values,q_values)
11. try:
12. history=[x for x in series]
13. predictions=list()
14. for t in range(4):
15. model=ARIMA(history,order=cfg)#order=(4,0,4)
16. model_fit=model.fit(disp=0)
17. yhat=model_fit.forecast()[0]
18. yh=mod(yhat[0])
19. predictions.append(yh)
20. history.append(yh)
21. except:
22. print("Error")
23. df1=df1[['SUBDIVISION','YEAR','ANNUAL']]
24. df1=df1.append(pd.DataFrame({'SUBDIVISION':[su
b,sub,sub,sub],'YEAR':[2018,2019,2020,2021],'ANN
UAL':predictions}))
25. fin=fin.append(df1,ignore_index=True)
3
The above functions are used to find the forecast values for There are two activities in the app, MainActivity and
the crop yield. These are predicted values. To make the values Results. The user has to fill the form fields on the
more realistic, we add little variation form the predicter MainActivity to move onto the Results activity. This activity
values. we are adding a random value in the range of 0% to uses the Search Dialog Android library to display the available
10% of the range of the crop yield from the year 2015 to 2018. entries for the fields, State, District, Crop (which is optional),
Area and Soil. The state and district can be filled with a
B. Forecasting Yield simple tap of a button which gets the latitude and longitude of
the user. The GPS coordinates are fetched using the Location
Here after reading the data in dataframedf, we are selecting
Manager API. The coordinates are then translated(using
the temperature, rainfall and production values for different
Geocoder) to the proper State name and District name.
districts for every crop. This is done by selecting dataframes
The filled entries are bundled and sent to the Results
of different crops ‘df1’, and selecting different districts where
activity. In this, the program queries the CSV file in the assets
the crop is grown ‘df2’. Store a copy of df2, for which append
folder of the app. This action does not require an active
the forecasted values.
Internet connection as the file is local. The CSV file is the
To figure out the forecast with greatest accuracy we are
output of the Machine Learning algorithms described in the
training 3 methods for each dataframe, and selecting one
paper earlier. If the crop field was left empty in the form, the
which gives the least error. Training the models is done by
search results in the best crop to be grown. Otherwise, the
80% of the available data. This is split randomly using the
search returns the information about the requested crop.
‘test_train_split’ function in the ‘sklearn’ module. Since this
The results are presented in a tabular format, with the
process selects test and train datasets at random, the model is
columns, Year, Predicted Production, Rainfall and
trained 5 times with different test train datasets. First train the
Temperature. The data shown is available for the years, 2019
SVR model with rbf kernel then find the confidence of the
to 2021. Two plots are drawn in the same activity, depicting
model. Confidence of themodel is the accuracy of the model.
the variation of Production and Rainfall with time. The plots
If the accuracy of this model is higher than the accuracy of the
are made using the GraphView library and the predicted
most accurate model yet, stored in ‘high’, then the high is
values are distinguished from the past values in the dataset by
given the value of confidence and the trained model is saved
use of different colours.
in the pickle called ‘crop.pickle’. Now the SVR model is
trained with the linear kernel. Here as well the proposed
system will find the confidence of the model and if it is more
than ‘high’, it will overwrite the previous pickle with the
better model. Repeat this process 5 times to get the model with
the best confidence.
Now train the linearregression model. Again test if the
confidence of this model is better than the currently best
model and if it is save this model in the pickle. Now read the
model from the pickle and save it in ‘clf’. This model has the
best accuracy. To forecast the yield the proposed model use
the predict function and pass the X_lately values. These are
the values of rainfall, temperature and current yield for the
years 2016, 2017, 2018. The output is a list containing 3
numbers which are the production values for the years 2019,
2020, 2021. This is appended to the ‘df3’ dataframe, which is
appended to the final dataframe.
This process is performed for all the districts where each of
the crop is grown. The output is stored in a csv file.
V. APPLICATION DESCRIPTION
An Android app has been developed to query the results of
the machine learning analysis. The app is compatible with Fig. 2: Main Activity Query Form
Android OS version 4.1.x (JELLY_BEAN) and higher. This
makes sure that app runs on 99.5% of all the Android devices
and it would penetrate the farmer demographic. The app has a
simple, easy-to-use interface requiring only a few taps to
retrieve the desired results.
4
As shown in above figure 4user enters all details with
specific crop then result shows the predicted production for
that region based on temperature soil type and rainfall as
shown in figure 5.
Fig. 4: Main Activity Query Form Fig. 6: Maize prediction for Bagalkot district in tons
5
networks“, Precision Agric (2006) 7: 117.
https://doi.org/10.1007/s11119-006-9004-y
[2] ShamsollahAyoubi&KanwarLalSahrawat (2011)” Comparing
multivariate regression and artificial neural network to predict barley
production from soil characteristics in northern Iran”, Archives of
Agronomy and Soil Science, 57:5, 549-
565, DOI: 10.1080/03650341003631400.
[3] BoyanKuangAbdulM.Mouazen,” Non-biased prediction of soil organic
carbon and total nitrogen with vis–NIR spectroscopy, as affected by soil
moisture content and texture“,Biosystems Engineering Volume 114,
Issue 3, March 2013, Pages 249-258, Elsevier,
https://doi.org/10.1016/j.biosystemseng.2013.01.005
[4] Pantazi X.E., Moshou D., Mouazen A.M., Kuang B., Alexandridis T.
(2014), ” Application of Supervised Self Organising Models for Wheat
Yield Prediction”, Artificial Intelligence Applications and Innovations.
AIAI 2014.IFIP Advances in Information and Communication
Technology, vol 436. Springer, Berlin, Heidelberg.
[5] Andrew Crane-Droesch, “ Machine learning methods for crop yield
Fig. 7: Wheat prediction for Bidar district in tons
prediction and climate change impact assessment in agriculture”,
Environmental Research Letters 2018, 13 114003.
REFERENCES
[1] Miao, Y., Mulla, D.J. & Robert, P.C, “Identifying important factors
influencing corn yield and grain quality variability using artificial neural