Logo

dev-resources.site

for different kinds of informations.

Predicting Environment Impact of Food Production caused by C02 Emission

Published at
10/31/2022
Categories
hacktoberfest
mindsdb
machinelearning
aws
Author
tesprogram
Author
10 person written this
tesprogram
open
Predicting Environment Impact of Food Production caused by C02 Emission

Introduction

In this tutorial, we will be predicting the C02 emissions and their impact on food production with MindsDB. MindsDB is an open-source machine-learning tool that brings automated machine learning to your database. MindsDB offers predictive capabilities in your database.

To complete this tutorial, you are required to have a working MindsDB connection, either locally or viaĀ cloud.mindsdb.com. You can use thisĀ guideĀ to connect to the MindsDB cloud.

Data Setup

Connecting the data as a file

Follow the steps below to upload a file to MindsDB Cloud.

  • Log in to yourĀ MindsDB CloudĀ account to open the MindsDB Editor.
  • Navigate toĀ Add dataĀ the section by clicking theĀ Add dataĀ button located in the top right corner.

Add Data

  • Choose the File tab File Upload
  • Choose theĀ Import FileĀ option.
  • Upload a file Food_Production.csv, name a table used to store the file data (here it isĀ Food_Production), and click theĀ Save and ContinueĀ button. File Upload
  • Once you are done uploading, you can query the data directly with the;
SELECT * FROM files.Food_Production LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

Table Query

Understanding the Dataset

Context

As the worldā€™s population has expanded and gotten richer, the demand for food, energy, and water has seen a rapid increase. Not only has demand for all three increased, but they are also strongly interlinked: food production requires water and energy; traditional energy production demands water resources; agriculture provides a potential energy source. This article focuses on the environmental impacts of food. Ensuring everyone in the world has access to a nutritious diet in a sustainable way is one of the greatest challenges we face.

Content

This dataset contains most 43 most common foods grown across the globe and 23 columns as their respective land, water usage, and carbon footprints.

Columns

  1. Land use change - Kg CO2 - equivalents per kg product
  2. Animal Feed - Kg CO2 - equivalents per kg product
  3. Farm - Kg CO2 - equivalents per kg product
  4. Processing - Kg CO2 - equivalents per kg product
  5. Transport - Kg CO2 - equivalents per kg product
  6. Packaging - Kg CO2 - equivalents per kg product
  7. Retail - Kg CO2 - equivalents per kg product

These represent greenhouse gas emissions per kg of food product(Kg CO2 - equivalents per kg product) across different stages in the lifecycle of food production.

Eutrophication ā€“ the pollution of water bodies and ecosystems with excess nutrients ā€“ is a major environmental problem. The runoff of nitrogen and other nutrients from agricultural production systems is a leading contributor.

Acknowledgments and Credits

https://ourworldindata.org

Credit: Vivek

Original Source: *Environment Impact of Food Production*

Creating the Predictor

To being, letā€™s create a predictor that uses the columns to predict CO2 emission. You can learn more about creating a predictor by checkingĀ here. You can predict a classification series model using the following syntax

CREATE PREDICTOR mindsdb.[predictor_name]
FROM [integration_name]
    (SELECT [sequential_column], [partition_column], [other_column], [target_column]
     FROM [table_name])
PREDICT [target_column]
Enter fullscreen mode Exit fullscreen mode
  • CREATE PREDICTOR: Creates a predictor with the nameĀ predictor_nameĀ in theĀ mindsdbĀ table.
  • FROM files: Points to the table containing the data.
  • PREDICT: Dictates the column to predict.
CREATE PREDICTOR mindsdb.CO2_emission
FROM files (SELECT * FROM files.Food_Produuction)
PREDICT Total_emissions
Enter fullscreen mode Exit fullscreen mode

On execution we get:

Query successfully completed
Enter fullscreen mode Exit fullscreen mode

Status of a Predictor

A predictor may take a couple of minutes for the training to complete. You can monitor the status of the predictor by using this SQL command:

SELECT status
FROM mindsdb.predictors
WHERE name='CO2_emission';
Enter fullscreen mode Exit fullscreen mode

Your output should be:

+------------+
| status     |
+------------+
| complete   |
+------------+
Enter fullscreen mode Exit fullscreen mode

Making Predictions

Now that we have our Prediction Model, we can simply execute some simple SQL query statements to predict the target value based on the feature parameters:

Making a Single Prediction

You can make predictions by querying the predictor as if it were a table. TheĀ SELECTĀ statement lets you make predictions for theĀ CO2_emissionĀ on the chosen feature parameter.

SELECT Total_emissions, Total_emissions_explain
FROM mindsdb.CO2_emission
WHERE Food_Product = 'Rice'
AND Land_use_charge = 0
AND Animal_Feed = 0
AND Farm = 1.4
AND Processing = 0.1
AND Transport = 0.1
AND Packaging = 0.1
AND Retail = 0.3
Enter fullscreen mode Exit fullscreen mode

Single Prediction

Making a Bulk Prediction

Now letā€™s make bulk predictions or multiple predictions to predict theĀ CO2_emissionĀ by joining our table with the model.

SELECT * FROM mindsdb.CO2_emission
JOIN files.Food_Production
LIMIT 100;
Enter fullscreen mode Exit fullscreen mode

Expected output should be:
Batch Predictions

Whatā€™s Next?

Have fun while trying it out yourself!

Give a like or a comment if this tutorial was helpful

mindsdb Article's
30 articles in total
Favicon
What is a Mind
Favicon
Mind Your Manners: How Politeness Can Make AI Smarter
Favicon
AutoGenius: AI-Powered Car Valuation and Trading Assistant
Favicon
How to build your Developer Portfolio with MindsDB: The symbiotic relationship between developers and Opensource in 2024.
Favicon
Deploying a MindsDB-powered PostgreSQL database on Vercel
Favicon
AI-Powered Selection of Asset Management Companies using MindsDB and LlamaIndex
Favicon
Using Large Language Models inside your database with MindsDB
Favicon
Measure Customer Support Sentiment Analysis with GPT, Airbyte and MindsDB
Favicon
Harnessing the Dual LLM Pattern for Prompt Security with MindsDB
Favicon
Unveiling the Dark Side of AI: How Prompt Hacking Can Sabotage Your AI Systems
Favicon
How to add AI image generation to your application
Favicon
Introducing MindsDB Playground: Your all-in-one MindsDB Companion App
Favicon
How to Make a Gmail Bot with a persona using OpenAI GPT and MindsDB
Favicon
Tutorial to Predict the Type of Glass using MongoDB
Favicon
Tutorial to Predict the Rating of Cars using Mindsdb and MongoDB
Favicon
Tutorial to Predict Gold Prices using Mindsdb and MongoDB
Favicon
How Developers should take advantage of MindsDB's Integration with OpenAI Chat GPT-3
Favicon
Tutorial to Predict the Energy Usage using MindsDB and MongoDB
Favicon
Extract Insights from Text Data inside Databases using OpenAI GPT-3 and MindsDB Integration
Favicon
Classify and label text in your database with Hugging Face and MindsDB integration
Favicon
How to predict purchase intent using SQL
Favicon
Everything You Need to Know about Open-Source Predictive Analytics Platform MindsDB
Favicon
Predicting gold prices with MindsDB and MongoDB
Favicon
Using MindsDB for Time Series Forecasting - Honey Production in the USA
Favicon
Predict Diamond prices with SQL Alchemy and MindsDB
Favicon
Tutorial to Predict the Weather Using MindsDB and MongoDB
Favicon
Predicting Environment Impact of Food Production caused by C02 Emission
Favicon
Predicting & Visualizing Gas Prices with MindsDB and Tableau
Favicon
Predicting & Visualizing Petroleum Production with MindsDB and Tableau
Favicon
Tutorial to Predict the Genre of Books using MindsDB [Mongo API]

Featured ones: