Giter VIP home page Giter VIP logo

decentralizedaqi's Introduction

Decentralized Air Quality Classifier

A Decentralized Air Quality Index Predictor using sensor values for a list of pollutants
This repository contains an Machine Learning DApp developed using cartesi rollups.

Static Badge Static Badge Static Badge

This example shows a simple way of leveraging some of the most widely used Machine Learning libraries available in Python.

The DApp generates a linear regression model using scikit-learn, NumPy and pandas, and then uses m2cgen (Model to Code Generator) to transpile that model into native Python code with no dependencies. This approach is inspired by Davis David's Machine Learning tutorial, and is useful for a Cartesi DApp because it removes the need of porting all those Machine Learning libraries to the Cartesi Machine's RISC-V architecture, making the development process easier and the final back-end code simpler to execute.

The practical goal of this application is to predict a classification based on the Air Quality Dataset, which contains the responses of a gas multisensor device deployed on the field in an Italian city. Hourly response averages are recorded along with gas concentration references from a certified analyzer.

The model currently takes into account several variables for predicting the AQI(Air quality index):

  1. PT08.S1(CO): This represents the sensor response to Carbon Monoxide (CO) levels in the air.

  2. PT08.S2(NMHC): This represents the sensor response to Non-Methane Hydrocarbons (NMHC) in the air. For instance, the value 1046 is the sensor reading, which can be correlated to the actual concentration of NMHC in micrograms per cubic meter (µg/m³).

  3. PT08.S3(NOx): This represents the sensor response to Nitrogen Oxides (NOx) in the air. For instance, the value 1056 is the sensor reading, which can be correlated to the actual concentration of NOx in parts per billion (ppb).

  4. PT08.S4(NO2): This represents the sensor response to Nitrogen Dioxide (NO2) in the air. For instance, the value 1692 is the sensor reading, which can be correlated to the actual concentration of NO2 in micrograms per cubic meter (µg/m³).

  5. PT08.S5(O3): This represents the sensor response to Ozone (O3) in the air. For instance, the value 1268 is the sensor reading, which can be correlated to the actual concentration of O3 in micrograms per cubic meter (µg/m³).

  6. T: This represents the temperature in degrees Celsius. For instance, the value 21.6 is the measured temperature.

  7. RH: This represents the Relative Humidity in percentage. For instance, the value 13.6 is the measured relative humidity.

  8. AH: This represents Absolute Humidity, which is the total water content in the air. For instance, the value 0.76 could be the absolute humidity in grams per cubic meter (g/m³).

As such, inputs to the DApp should be given as a JSON string such as the following:

{"PT08.S1(CO)": 1360, "PT08.S2(NMHC)": 1046, "PT08.S3(NOx)": 1056, "PT08.S4(NO2)": 1692, "PT08.S5(O3)": 1268, "T": 21.6, "RH": 13.6, "AH": 0.76}

Interacting with the application

We have two main ways to interact with the dapp: using the frontend-web-cartesi application, or using the sunodo send command.

frontend-web-cartesi

Clone the repository in the above link. After that, go to a separate terminal window and switch to the frontend-web-cartesi directory:

cd frontend-web-cartesi

Run the following commands to run the frontend web in your localhost:

yarn
yarn codegen
yarn start

Runs the app in the development mode. Open http://localhost:3000 to view it in the browser.

Please keep in mind that you should import one of the local wallets to the metamask.With that in place, also add the sunodo token to your wallet.

**Note: you must deposit some Sunodo tokens to the wallet inside the dApp to be able to use the AQI prediction fuction. **

Changing the application

This DApp was implemented in a rather generic way and, as such, it is possible to easily change the target dataset as well as the predictor algorithm.

To change those, open the file airquality/model/build_model.py and change the following variables defined at the beginning of the script:

  • model: defines the scikit-learn predictor algorithm to use. While it currently uses sklearn.linear_model.LinearRegression, many other possibilities are available, from several types of linear regressions to solutions such as support vector machines (SVMs).
  • train_csv: a URL or file path to a CSV file containing the dataset. It should contain a first row with the feature names, followed by the data.

decentralizedaqi's People

Contributors

marcusmugen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.