Skip to content

Retinpkumar/Agricultural-N2O-Predictor-App

Repository files navigation

🌱 Agricultural N2O flux Predictor App

The app predicts the amount of Agricultural Nitrous Oxide flux released into the atmosphere from intensively managed cropping systems.

📖 Table of Contents

Table of Contents
  1. ➤ Motivation
  2. ➤ Folder Structure
  3. ➤ Model used
  4. ➤ Challenges faced
  5. ➤ Building the app
  6. ➤ Running the app locally

---

🎯 Motivation

Nitrous Oxide is one of the potent greenhouse gas that is accumulating in the atmosphere at extraordinary rates. This can be largely attributed to intensification of agricultural cropping systems where the cultivated soil contribute almost 60% of the agricultural flux.

Though there were previous attempts at identifying and quantifying the agricultural Nitrous Oxide flux, these attempts could only predict the results with an R2-score ranging from 25-40%. The model used in this app is aimed at outperforming the previous models and has been able to succesfully produce the results with almost 78% R2-score.

---

📂 Folder Structure

Agricultural-N2O-Predictor-App
|
|—— .streamlit
|    |—— config.toml
|
|—— data
|    |—— Saha_et_al_2020_ERL_Data.xlsx
|    |—— processed_data.csv
|
|—— images
|    |—— app_recording.gif
|    |—— app_working.png
|    |—— sidebar_image.png
|    |—— title_image.jpg
|
|—— model
|    |—— explained_shapvalues.pickle
|    |—— explainer.pickle
|    |—— features.pickle
|    |—— final_model.pickle
|    |—— scaled_df.pickle
|    |—— scaler.pickle
|
|—— notebooks
|    |—— Agri_N2O_Notebook.ipynb
|
|—— plots
|    |—— airt_dep_plot.png
|    |—— dafsd_dep_plot.png
|    |—— force_plot.png
|    |—— nh4_dep_plot.png
|    |—— no3_dep_plot.png
|    |—— pp7_dep_plot.png
|    |—— som_dep_plot.png
|    |—— summaryplot.png
|    |—— wfps_dep_plot.png
|
|—— src
|    |—— explain_model.py
|    |—— model.py
|    |—— multipage.py
|    |—— scaler.py
|
|—— .gitignore
|—— Procfile
|—— README.md
|—— app.py
|—— model_form.py
|—— requirements.txt
|—— runtime.txt
|—— setup.sh

---

💻 Model Used

The app uses a machine learning model known as "Random Forest Regressor" for making the prediction. Random Forest belongs to tree based ensemble models category and hence it is tough to interpret the final output of the model.

Hence, I have used an explainable AI tool known as "SHAP" for understanding the model and interpreting the output.

Check the app for more detailed explanation of the model and the predicted output.

---

🧩 Challenges faced

  • The data that quantified Nitrous Oxide flux was heavily right skewed and also contained few negative values.
  • The data for Water frontage pore space, Ammonia and Nitrate had some values missing.
  • Vegetation data was highly imbalanced with almost 84% of the data were recorded for Corn. Data for Wheat and Soy constituted only about 8.5 and 7.5% each.

---

📚 Building the app

The app was built using Python3.8 and with the help of Streamlit library. Other major libraries used include:
  • Numpy
  • Pandas
  • Matplotlib
  • Scikit-learn
  • Shap
The app is currently deployed on Heroku.

---

💾 Running the app locally

  • Inside a new directory clone the files from the repo using
    https:/Retinpkumar/Agricultural-N2O-Predictor-App.git

  • Create a new virtual environment and activate it.

  • Open the terminal and install the libraries and dependancies using
    pip install -r requirements.txt

  • Start and run the app by entering the code given below in the terminal
    streamlit run app.py

---

For further discussions and queries, contact me at: [email protected]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages