DEV Community

Cover image for AI enthusiasm #5 - Calculate your carbon footprint🌱
Astra Bertelli
Astra Bertelli

Posted on

AI enthusiasm #5 - Calculate your carbon footprint🌱

What is the carbon footprint and why is it important?

Carbon footprint is defined as the quantity of carbon dioxide (CO2) emitted by someone (a person, an institution, a factory, a State...).

As reported in a recent commentary by Cozzi, Chen and Kim (published here on IEA) an average person produces 4.7 tons of CO2 per year, with the top 1% richest people producing 1000 times more carbon dioxide than the 1% poorest ones. All considered, this is an insane amount of CO2, and the situation is not going to improve as more and more countries enter their consumeristic era.

Knowing your carbon footprint is, in this sense, key to save the planet: knowledge is power, and the power in this case should be used to reduce your impact on the planet.

We need, then, a fast and reliable method to calculate our carbon footprint, and, as usual, we can use an AI-related approach to help solving this issue, and we'll do it codeless.

Building your first Decision Tree Regressor

We'll start from a well-documented Kaggle dataset, "Individual carbon footprint calculation", by Mesut Duman and collaborators. The fields reported are described as follows by the maintainers themselves:

  • 'Body Type': Body type.
  • 'Sex': Gender.
  • 'Diet': Diet.
  • 'How Often Shower': Frequency of showering
  • 'Heating Energy Source': Residential heating energy
  • 'Transport': Transportation preference.
  • 'Vehicle Type': Vehicle fuel type.
  • 'Social Activity': Frequency of participating in social activities.
  • 'Monthly Grocery Bill': Monthly amount spent on groceries, in dollars.
  • 'Frequency of Traveling by Air': Frequency of using aircraft in the last month.
  • 'Vehicle Monthly Distance Km': The kilometers traveled by vehicle in the last month.
  • 'Waste Bag Size': Size of the garbage bag
  • 'Waste Bag Weekly Count': The amount of garbage thrown away in the last week.
  • 'How Long TV PC Daily Hour': Daily time spent in front of TV or PC.
  • 'How Many New Clothes Monthly': Number of clothes purchased monthly.
  • 'How Long Internet Daily Hour': Time spent on the Internet daily.
  • 'Energy efficiency': Whether or not you care about purchasing energy efficient devices.
  • 'Recycling': The wastes it recycles.
  • 'Cooking_With': Devices used in cooking
  • 'CarbonEmission': Dependent variable, total carbon emissions.

The carbon emissions are measured in kgCO2e/month.

We want to get the carbon emissions from all the fields in the dataset, which are a mixture of categorical and numerical data.

In order to do so, we need to exploit a regressor, a machine learning model that finds the best way to fit the dependent variable on the independent ones.

We could implement it by writing some code, but since Hugging Face gives us the opportunity to train our models codeless with Autotrain, why don't we exploit it?

We head over to Autotrain, then, we upload the dataset we downloaded from Kaggle, we choose "Tabular regression" as task and "decision tree" as model: this is the most basic regressor one could think of, but still one of the best for our purposes.

The training takes a couple of minutes, and then we get the tabular regressor pushed to our HF account. You can find the example one that I trained here.

As you can see from the metrics of this example, the R squared (which measures the proportion of the variance in the dependent variable that is predictable from the independent variables: it provides an indication of how well the model fits the data), is really close to 1, which means that the model is really good at predictions. The MAE (mean absolute error) is about 76, which means that on average the model predicts values that are within a +/-76 kg/month range from the true ones.

You built your first decision tree regressor! Now you can exploit it to make predictions, and you can do it in the Hugging Face space that I set up for the purpose: https://huggingface.co/spaces/as-cle-bert/carbon-footprint-predictor.

Let me know in the comments below what is your carbon footprint and what you plan to do to reduce it, if you please!🌱

Cover image from Wynes and Nicolas (2017)

Top comments (0)