{"id":14958100,"url":"https://github.com/astrocvijo/power_consumption_prediction","last_synced_at":"2025-10-24T14:30:47.253Z","repository":{"id":254350080,"uuid":"846273778","full_name":"AStroCvijo/Power_Consumption_Prediction","owner":"AStroCvijo","description":"Future power consumption prediction using LSTM, GRU and Transformer models","archived":false,"fork":false,"pushed_at":"2024-08-30T21:17:13.000Z","size":1574,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-10T07:43:16.527Z","etag":null,"topics":["deep-learning","experiment","forecasting","gru","lstm","machine-learning","python","pytorch","time-series","transfomer"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AStroCvijo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-22T21:43:26.000Z","updated_at":"2024-09-02T11:32:32.000Z","dependencies_parsed_at":"2024-09-22T06:01:24.150Z","dependency_job_id":"546786eb-6ade-4e13-9033-2df96ef49fe7","html_url":"https://github.com/AStroCvijo/Power_Consumption_Prediction","commit_stats":{"total_commits":21,"total_committers":2,"mean_commits":10.5,"dds":0.04761904761904767,"last_synced_commit":"d8612b0f642a809a704da884a372f17a1f7bbb24"},"previous_names":["astrocvijo/power_consumption"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AStroCvijo%2FPower_Consumption_Prediction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AStroCvijo%2FPower_Consumption_Prediction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AStroCvijo%2FPower_Consumption_Prediction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AStroCvijo%2FPower_Consumption_Prediction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AStroCvijo","download_url":"https://codeload.github.com/AStroCvijo/Power_Consumption_Prediction/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219868597,"owners_count":16555871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","experiment","forecasting","gru","lstm","machine-learning","python","pytorch","time-series","transfomer"],"created_at":"2024-09-24T13:16:13.863Z","updated_at":"2025-10-24T14:30:45.898Z","avatar_url":"https://github.com/AStroCvijo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Power Consumption prediction\n\n## Overview \nThis project aims to predict future power consumption using advanced machine learning models such as **LSTM**, **GRU**, and **Transformer**. Accurate power consumption forecasts can improve energy management, reduce operating costs, and improve grid stability in various zones. The dataset contains 52,416 observations collected over 10-minute intervals, and each observation has 9 feature columns describing energy usage and relevant factors. \nAdditional info on the dataset can be found [HERE](https://www.kaggle.com/datasets/fedesoriano/electric-power-consumption).  \n\nDate of creation: August, 2024 \u003cbr/\u003e\n\n##  Model Selection \n- **LSTM (Long Short-Term Memory)**: LSTM models are well-suited for long-term dependencies in time series data by mitigating the vanishing gradient problem. They excel in capturing both short and long-term trends. \n- **GRU (Gated Recurrent Units)**: GRUs are a simpler alternative to LSTM, with fewer parameters and faster training times. They balance the performance and complexity trade-off in time series forecasting. \n- **Transformer**: With its self-attention mechanism, the Transformer model is highly effective in modeling long-range dependencies in time series data. It scales well with large datasets and can learn complex temporal relationships.\n\n\n## Quickstart\n\n1. Clone the repository:\n    ```bash\n    git clone https://github.com/AStroCvijo/power_consumption_prediction\n    ```\n\n2. Download the [Electric Power Consumption dataset](https://www.kaggle.com/datasets/fedesoriano/electric-power-consumption), extract it, and paste the `.csv` file into the `Power_Consumption_Prediction/data` directory.\n\n3. Navigate to the project directory:\n    ```bash\n    cd power_consumption_prediction\n    ```\n\n4. Create a virtual environment:\n    ```bash\n    python -m venv venv\n    ```\n\n5. Activate the virtual environment:\n    - **Linux/macOS**:\n      ```bash\n      source venv/bin/activate\n      ```\n    - **Windows**:\n      ```bash\n      venv\\Scripts\\activate\n      ```\n\n6. Install the required packages:\n    ```bash\n    pip install -r requirements.txt\n    ```\n\n7. Train the model using the default settings:\n    ```bash\n    python main.py --train\n    ```\n\n\n## Arguments guide \n\n### Training arguments\n`-t or --train` specify you want to train the model  \n`-e or --epochs` number of epochs in training  \n`-lr or --learning_rate` learning rate in training  \n\n### Data arguments\n`-sl or --sequence_length` length of the sequences extracted from the data  \n`-ps or --prediction_step` how far in the future to predict (1 = 10min, 10 = 100min)  \n`-pt or --prediction_target` which of the three zones' power consumption to predict: `PowerConsumption_Zone1`, `PowerConsumption_Zone2`, or `PowerConsumption_Zone3`\n\n### Model arguments\n`-m or --model` followed by the model you want to use: `LSTM`, `GRU`, or `Transformer`  \n`-mn or --model_name` followed by the name of the model you want to use  \n`-l or --load` followed by the path to the model you want to load  \n\n#### LSTM and GRU specific arguments\n`-hs or --hidden_size` size of the hidden layer in the LSTM or GRU models  \n`-nl or --number_of_layers` number of layers in the LSTM or GRU models  \n\n#### Transformer specific arguments\n`-md or --model_dimensions` dimensions of the Transformer model  \n`-ah or --attention_heads` number of attention heads in the Transformer model\n\n## How to Use\n\n ### Training Example: \n`python main.py --train --model LSTM --epochs 10 --learning_rate 0.001 --sequence_length 60 --prediction_step 10 --prediction_target PowerConsumption_Zone3 --hidden_size 100 --number_of_layers 3`\n\n### Loading a Pre-Trained Model example\n`python main.py --load pretrained_models/LSTM_model.pth --model LSTM --sequence_length 60 --prediction_step 10 --prediction_target PowerConsumption_Zone3 --hidden_size 100 --number_of_layers 3`\n\n## Model Performance\n The models were evaluated based on the following metrics: \n - **Test Loss**: Indicates how well the model performs on unseen data.\n - **Mean Squared Error (MSE)**: Punishes larger errors by squaring the differences. \n - **Mean Absolute Error (MAE)**: Measures the average magnitude of errors in predictions. \n \n| Model | Test Loss | MSE | MAE|\n|--------------|-----------|-------|-------|\n| LSTM | 0.0009 | 0.0011| 0.1735| \n| GRU | 0.0012 | 0.0009| 0.1718 | \n| Transformer | 0.0136| 0.0138| 0.1934|\n\n#### LSTM (Long Short-Term Memory)\nThe LSTM model performed the best, achieving the lowest test loss (0.0009) and a competitive MAE (0.0011). This suggests that LSTM effectively captured both short and long-term dependencies, leading to accurate predictions of power consumption. \n \n#### GRU (Gated Recurrent Units)\nGRU also showed strong performance, with a slightly higher test loss (0.0012) than LSTM but the lowest MAE (0.0009) and MSE (0.1718). This indicates GRU is highly efficient in reducing prediction errors and is a strong alternative to LSTM. \n\n#### Transformer\nThe Transformer model struggled with this task, showing a significantly higher test loss (0.0136), MAE (0.0138), and MSE (0.1934). This may be due to the model's complexity and its need for more data to fully utilize its attention mechanism.\n\n## Visualization\n\nPredictions vs ground truth data for **PowerConsumption_Zone3**, forecasting 10 hours in advance.\n\n![Predictions vs Ground Truth](images/image1.png)  \n*Test Loss*: 0.0010  \n*Mean Absolute Error (MAE)*: 0.1742  \n\n**Model Details**:  \n- **Model**: LSTM  \n- **Hidden Size**: 75  \n- **Number of Layers**: 2  \n- **Epochs**: 5  \n- **Learning Rate**: 0.001  \n\n## Folder Tree\n\n```\nPower_Consumption_Prediction\n├── data\n│   ├── data_functions.py     # Contains functions for data preprocessing, loading, and transformation\n│   └── powerconsumption.csv  # The dataset file\n├── models\n│   ├── GRU.py                # GRU model implementation\n│   ├── LSTM.py               # LSTM model implementation\n│   └── Transformer.py        # Transformer model implementation\n├── pretrained_models         # Directory for saving and loading pre-trained models\n├── train\n│   ├── evaluation.py         # Script to evaluate model performance\n│   └── train.py              # Script to train and save models\n├── utils\n│   └── argparser.py          # Contains argument parsing logic for CLI inputs\n└── main.py                   # Main script to run the project\n```\n\n## References\n\nfedesoriano. (August 2022). Electric Power Consumption. Retrieved [Date Retrieved] from https://www.kaggle.com/datasets/fedesoriano/electric-power-consumption.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastrocvijo%2Fpower_consumption_prediction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fastrocvijo%2Fpower_consumption_prediction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastrocvijo%2Fpower_consumption_prediction/lists"}