Skip to content

This repository houses an Energy Forecasting API that uses Machine Learning to predict daily and monthly energy consumption from historical data. It's designed as a practical demonstration of a Machine Learning Engineering workflow, from initial analysis to a deployable API packaged with Docker.

Notifications You must be signed in to change notification settings

labrijisaad/Monthly-Daily-Energy-Forecasting-Docker-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

513a318 ยท Mar 28, 2024

History

22 Commits
Mar 21, 2024
Mar 24, 2024
Mar 25, 2024
Mar 23, 2024
Mar 24, 2024
Mar 24, 2024
Mar 21, 2024
Mar 24, 2024
Mar 28, 2024
Mar 23, 2024

Repository files navigation

Monthly & Daily Energy Forecasting Docker API โšก

This image, generated with DALL-E, depicts tradition and tomorrow dance under a future-woven sky.

๐Ÿ“˜ Introduction

This project is all about predicting energy use ๐Ÿ”Œ. It began with a simple CSV file ๐Ÿ“, and I worked through steps like analyzing the data (EDA), using machine learning for predictions ๐Ÿค–, and finally creating a Dockerized API ๐Ÿณ. This journey represents a common task for Machine Learning Engineers: transforming data analysis into a usable API. I developed two prediction models: one for the next day ๐Ÿ“† and another for the next 30 days ๐Ÿ—“๏ธ, both based on historical data.

๐ŸŽฏ Objectives

Here's what I aimed to achieve:

  • Understand and Prepare a raw CSV dataset ๐Ÿ“.
  • Build models to forecast energy use for the upcoming day and month ๐Ÿ”ฎ.
  • Package these models into an API, making it straightforward for others to use, encapsulated in Docker ๐Ÿ“ฆ.
  • Allow using data with the Docker-contained API through Docker volumes.

Preparation Before Building the API ๐Ÿ› ๏ธ

Prior to constructing the API within the src folder, I put together and described my work in Jupyter notebooks ๐Ÿ““, found in the notebooks directory. These notebooks explain my steps:

๐Ÿงœโ€โ™‚๏ธ Development Workflow

Below is a Mermaid Diagram outlining the Development Workflow.

Loading
graph LR
    classDef processNode fill:#4F5D75,stroke:#EF8354,stroke-width:2px,color:#FFFFFF;

    B[EDA & Data Prep - Notebook]
    B --> C[Machine Learning - Notebook]
    C --> D[API Simulation - Notebook]
    D --> E[API Development]
    E -->|Dockerized| F[Docker Environment]
    E -->|Virtual Env/Conda| G[Virtual Environment/Conda]
    F --> H[Test and Use API]
    G --> H

    class A,B,C,D,E,F,G,H processNode;

๐Ÿ—๏ธ API Construction

After prototyping in the API - Energy_Forecasting Notebook, Here is how i designed the project structure:

Energy-Forecast-API/
โ”‚
โ”œโ”€โ”€ docker/                                 # Docker configuration files
โ”‚   โ”œโ”€โ”€ Dockerfile                          # Instructions for building the Docker image
โ”‚   โ””โ”€โ”€ requirements.txt                    # API dependencies for the Docker image
โ”‚
โ”œโ”€โ”€ src/                                    # Source code for the API
โ”‚   โ”œโ”€โ”€ __init__.py                         
โ”‚   โ”œโ”€โ”€ energy_forecasting.py               # Main script for energy forecasting logic
โ”‚   โ””โ”€โ”€ models/                             
โ”‚       โ”œโ”€โ”€ __init__.py                     
โ”‚       โ”œโ”€โ”€ base_energy_model.py            # Base class for energy models
โ”‚       โ”œโ”€โ”€ short_term_energy_model.py      # Short-term energy forecasting model
โ”‚       โ””โ”€โ”€ long_term_energy_model.py       # Long-term energy forecasting model
โ”‚
โ”œโ”€โ”€ notebooks/                              
โ”‚   โ”œโ”€โ”€ EDA_Data_Preparation.ipynb          # Exploratory Data Analysis and Data Preparation
โ”‚   โ”œโ”€โ”€ ML_Experimentation.ipynb            # Machine Learning model experimentation
โ”‚   โ””โ”€โ”€ API_Design.ipynb                    # Development of class-based API in notebook form
โ”‚
โ”œโ”€โ”€ data/                                   
โ”‚   โ”œโ”€โ”€ raw/                                # Unprocessed initial data
โ”‚   โ””โ”€โ”€ processed/                          # Processed data ready for analysis
โ”‚
โ”œโ”€โ”€ results/                                # Outputs from analysis and model training notebooks
โ”‚
โ”œโ”€โ”€ .env                                    # Environment variables for Docker and the application
โ”œโ”€โ”€ Makefile                                # Make commands for easy project setup and management
โ”œโ”€โ”€ requirements.txt                        # Project dependencies for development
โ”œโ”€โ”€ .gitignore                              # Specifies intentionally untracked files to ignore
โ””โ”€โ”€ README.md                               # Comprehensive guide to setup and use the API

๐Ÿš€ Run the Code

You're a few steps away from predicting energy usage! Choose one of the two setups based on your preference:

Option 1: Virtual Environment or Conda ๐ŸŒฟ

If you like the Python environment approach, here's how to proceed:

  1. Environment Setup: Confirm Python is up and ready, and set up your virtual environment or Conda.

  2. Dependency Installation: In the project's main folder, run:

    pip install -r requirements.txt

    This installs all required libraries specified in requirements.txt.

  3. Environment Activation: With dependencies in place, activate your environment to proceed.

  4. Running the Application: Your environment is now primed for action.

    To get a short-term energy prediction, enter:

    make test-short-term

    You'll get a forecast like this:

    Short-term prediction for '2010-05-17': 1512.24
    

    For custom date predictions, use:

    make long-term DATE=2010-05-17

    And expect a response similar to:

    Long-term prediction for 2010-05-17: 1509.71
    

For more commands, type make help in the terminal.

Option 2: Docker ๐Ÿณ

For Docker fans, make sure Docker is operational on your machine. You can containerize the app with ease ๐Ÿ˜‰

  • Build Docker Image:

    make docker-build

    Construct your Docker image before running forecasts.

  • Run Short-Term Forecast in Docker:

    make test-docker-run

    See a prediction output like:

    Short-term prediction for 2010-05-17: 1513.30
    
  • Run Custom Forecast in Docker:

    make docker-run DATE=2010-05-17 MODEL=long

    Get a custom forecast, for example:

    Long-term prediction for 2010-05-17: 1514.91
    

โš ๏ธ For further Docker commands, type make help in the terminal. If you wish to modify the command, including changing the docker volume path, you can do so in the Makefile. Just ensure you make these adjustments as needed.

๐ŸŒ Let's Connect!

You can connect with me on LinkedIn or check out my GitHub repositories:

About

This repository houses an Energy Forecasting API that uses Machine Learning to predict daily and monthly energy consumption from historical data. It's designed as a practical demonstration of a Machine Learning Engineering workflow, from initial analysis to a deployable API packaged with Docker.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published