surahj commited on
Commit
79b8226
·
1 Parent(s): 9ccab89

Add YAML metadata to README.md and create app.py entry point for HF Spaces

Browse files
Files changed (1) hide show
  1. README.md +110 -258
README.md CHANGED
@@ -1,58 +1,77 @@
1
- # Daily Household Electricity Consumption Predictor
2
-
3
- A web-based application designed to help Nigerian households estimate their daily electricity usage in Kilowatt-hours (kWh). This project serves as a practical learning vehicle for Machine Learning Operations (MLOps), covering the full lifecycle from data preparation and model training to deployment, monitoring, and continuous improvement.
4
-
5
- ## 🎯 Project Goals
6
-
7
- ### Business Goals
8
-
9
- - **Empower Households**: Provide users with a simple, accessible tool to understand and predict their daily electricity consumption
10
- - **Promote Energy Awareness**: Help users identify factors influencing their electricity usage, encouraging more efficient energy habits
11
- - **Inform Budgeting**: Enable users to better estimate their electricity bills, reducing financial surprises
12
- - **Foundational MLOps Learning**: Serve as a concrete project to apply and understand core MLOps principles
13
-
14
- ### Machine Learning & Technical Goals
15
-
16
- - **Accurate Prediction**: Develop a regression model capable of predicting daily kWh consumption with acceptable accuracy
17
- - **User-Friendly Interface**: Create an intuitive web interface that allows easy input of features and clear display of predictions
18
- - **Deployable Application**: Build a self-contained application that can be deployed to a public platform
19
- - **MLOps Readiness**: Design the application with modularity and best practices that facilitate future MLOps implementation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  ## 🏗️ Project Structure
22
 
23
  ```
24
- lin-re-model/
25
  ├── src/
26
- │ ├── __init__.py
27
- │ ├── data_generator.py # Synthetic data generation
28
- ├── model.py # ML model training and prediction
29
- │ └── app.py # Gradio web interface
30
  ├── tests/
31
- │ ├── __init__.py
32
- │ ├── test_data_generator.py # Data generator tests
33
- ├── test_model.py # Model tests
34
- ├── test_app.py # Application tests
35
- │ └── test_integration.py # Integration tests
36
- ├── requirements.txt # Python dependencies
37
- ├── pytest.ini # Pytest configuration
38
- ├── run_tests.py # Test runner script
39
- └── README.md # This file
40
  ```
41
 
42
- ## 🚀 Quick Start
43
-
44
- ### Prerequisites
45
 
46
- - Python 3.8 or higher
47
- - pip (Python package installer)
48
 
49
- ### Installation
50
-
51
- 1. **Clone the repository** (if not already done):
52
 
53
  ```bash
54
- git clone <repository-url>
55
- cd lin-re-model
56
  ```
57
 
58
  2. **Install dependencies**:
@@ -64,235 +83,67 @@ lin-re-model/
64
  3. **Run the application**:
65
 
66
  ```bash
67
- python src/app.py
68
  ```
69
 
70
- 4. **Open your browser** and navigate to `http://localhost:7860`
71
-
72
- ## 🧪 Testing
73
-
74
- This project includes comprehensive tests to ensure code quality and functionality. The test suite covers:
75
-
76
- - **Unit Tests**: Individual component testing
77
- - **Integration Tests**: End-to-end workflow testing
78
- - **Data Quality Tests**: Validation of synthetic data generation
79
- - **Model Performance Tests**: Verification of model accuracy and consistency
80
-
81
- ### Running Tests
82
-
83
- #### Option 1: Using the test runner script
84
-
85
- ```bash
86
- # Run all tests with coverage
87
- python run_tests.py
88
-
89
- # Run only unit tests
90
- python run_tests.py unit
91
-
92
- # Run only integration tests
93
- python run_tests.py integration
94
- ```
95
-
96
- #### Option 2: Using pytest directly
97
-
98
- ```bash
99
- # Run all tests
100
- pytest
101
-
102
- # Run with verbose output
103
- pytest -v
104
-
105
- # Run with coverage report
106
- pytest --cov=src --cov-report=html
107
-
108
- # Run specific test file
109
- pytest tests/test_model.py
110
-
111
- # Run specific test class
112
- pytest tests/test_model.py::TestElectricityConsumptionModel
113
-
114
- # Run specific test method
115
- pytest tests/test_model.py::TestElectricityConsumptionModel::test_train_model
116
- ```
117
-
118
- ### Test Coverage
119
-
120
- The test suite provides comprehensive coverage including:
121
-
122
- - **Data Generator Tests**:
123
-
124
- - Data generation with different parameters
125
- - Data splitting functionality
126
- - Data persistence (save/load)
127
- - Data quality validation
128
- - Reproducibility checks
129
-
130
- - **Model Tests**:
131
-
132
- - Model initialization and training
133
- - Feature preparation and validation
134
- - Prediction functionality
135
- - Model evaluation metrics
136
- - Model persistence (save/load)
137
- - Error handling
138
-
139
- - **Application Tests**:
140
-
141
- - Web interface functionality
142
- - User interaction flows
143
- - Error handling in UI
144
- - State management
145
-
146
- - **Integration Tests**:
147
- - Complete workflow testing
148
- - End-to-end functionality
149
- - Performance consistency
150
- - Data quality across components
151
-
152
- ### Expected Test Results
153
-
154
- When all tests pass, you should see output similar to:
155
-
156
- ```
157
- 🧪 Running Daily Household Electricity Consumption Predictor Tests
158
- ======================================================================
159
- ============================= test session starts ==============================
160
- platform linux -- Python 3.8.x, pytest-7.4.0, pluggy-1.0.0
161
- rootdir: /path/to/lin-re-model
162
- plugins: cov-4.1.0
163
- collected 45 tests
164
-
165
- tests/test_app.py ................... [ 42%]
166
- tests/test_data_generator.py ................... [ 78%]
167
- tests/test_integration.py .......... [100%]
168
-
169
- ---------- coverage: platform linux, python 3.8.x-final-0 -----------
170
- Name Stmts Miss Cover Missing
171
- ------------------------------------------------------------
172
- src/__init__.py 1 0 100%
173
- src/app.py 180 5 97% 180-185
174
- src/data_generator.py 95 2 98% 95-97
175
- src/model.py 180 8 96% 180-188
176
- ------------------------------------------------------------
177
- TOTAL 456 15 97%
178
-
179
- ============================== 45 passed in 5.23s ==============================
180
-
181
- ✅ All tests passed!
182
- ```
183
-
184
- ## 📊 Model Features
185
-
186
- The electricity consumption prediction model uses the following features:
187
-
188
- 1. **Average Daily Temperature** (°C): Numerical input (15-35°C range)
189
- 2. **Day of the Week**: Categorical input (Monday through Sunday)
190
- 3. **Major Event**: Boolean input (Holiday, Power Outage, etc.)
191
-
192
- ### Model Algorithm
193
-
194
- - **Algorithm**: Linear Regression
195
- - **Preprocessing**: StandardScaler for numerical features, OneHotEncoder for categorical features
196
- - **Evaluation Metrics**: MSE, RMSE, MAE, R²
197
-
198
- ## 🎮 Using the Application
199
-
200
- ### Step 1: Generate Data & Train Model
201
 
202
- 1. Navigate to the "Data Generation & Training" tab
203
- 2. Adjust parameters as desired:
204
- - Number of Data Points (100-5000)
205
- - Noise Level (0.01-0.5)
206
- - Training/Validation/Test Set Proportions
207
- 3. Click "Generate Data & Train Model"
208
- 4. Review the training metrics and evaluation results
209
 
210
- ### Step 2: Make Predictions
211
 
212
- 1. Navigate to the "Prediction" tab
213
- 2. Enter your parameters:
214
- - Average Daily Temperature (15-35°C)
215
- - Day of the Week
216
- - Major Event (checkbox)
217
- 3. Click "Predict Consumption"
218
- 4. View your estimated daily electricity consumption
219
 
220
- ### Step 3: Understand the Model
 
 
 
 
221
 
222
- 1. Navigate to the "Model Information" tab
223
- 2. Click "Show Model Information"
224
- 3. Review feature coefficients and model interpretation
225
 
226
- ## 🔧 Development
 
 
 
227
 
228
- ### Adding New Tests
229
 
230
- To add new tests:
 
 
 
 
231
 
232
- 1. **Unit Tests**: Add to appropriate test file in `tests/`
233
- 2. **Integration Tests**: Add to `tests/test_integration.py`
234
- 3. **Follow naming convention**: `test_<functionality>`
235
- 4. **Use descriptive docstrings**: Explain what the test validates
236
 
237
- ### Test Best Practices
238
 
239
- - **Isolation**: Each test should be independent
240
- - **Descriptive names**: Test names should clearly indicate what they test
241
- - **Assertions**: Use specific assertions with meaningful messages
242
- - **Coverage**: Aim for high test coverage (>95%)
243
- - **Performance**: Tests should run quickly (<10 seconds total)
244
 
245
- ### Running Tests in Development
246
 
247
- During development, you can run tests in different ways:
248
 
249
  ```bash
250
- # Quick test run (no coverage)
251
- pytest -x # Stop on first failure
252
-
253
- # Run tests in parallel (if pytest-xdist installed)
254
- pytest -n auto
255
-
256
- # Run tests with detailed output
257
- pytest -v -s
258
-
259
- # Run tests and watch for changes
260
- pytest-watch # Requires pytest-watch package
261
- ```
262
-
263
- ## 🚀 Deployment
264
 
265
- ### Local Deployment
 
266
 
267
- ```bash
268
- python src/app.py
269
  ```
270
 
271
- ### Hugging Face Spaces Deployment
272
-
273
- 1. Create a new Space on Hugging Face
274
- 2. Upload the project files
275
- 3. Configure the Space to run `python src/app.py`
276
- 4. The application will be available at your Space URL
277
-
278
- ## 📈 Future Enhancements
279
-
280
- ### MLOps Features (Future Phases)
281
-
282
- - **Data Versioning**: Implement DVC for data version control
283
- - **Experiment Tracking**: Integrate MLflow or Weights & Biases
284
- - **Model Registry**: Use MLflow Model Registry for model lifecycle management
285
- - **Containerization**: Create Dockerfile for reproducible environments
286
- - **CI/CD**: Set up GitHub Actions for automated testing and deployment
287
- - **Model Monitoring**: Implement monitoring for data drift and performance degradation
288
- - **Continuous Training**: Define triggers for automated retraining
289
 
290
- ### Model Improvements
291
-
292
- - **Feature Engineering**: Add more complex features (historical averages, time of day, etc.)
293
- - **Advanced Models**: Experiment with Random Forest, Gradient Boosting, etc.
294
- - **Hyperparameter Tuning**: Implement automated hyperparameter optimization
295
- - **Ensemble Methods**: Combine multiple models for better predictions
296
 
297
  ## 🤝 Contributing
298
 
@@ -300,15 +151,16 @@ python src/app.py
300
  2. Create a feature branch
301
  3. Make your changes
302
  4. Add tests for new functionality
303
- 5. Ensure all tests pass
304
- 6. Submit a pull request
305
 
306
- ## 📄 License
307
 
308
- This project is licensed under the MIT License - see the LICENSE file for details.
 
 
 
 
309
 
310
- ## 🙏 Acknowledgments
311
 
312
- - Gradio team for the excellent web interface framework
313
- - Scikit-learn team for the machine learning library
314
- - The MLOps community for best practices and guidance
 
1
+ ---
2
+ title: 'Electricity Consumption Predictor'
3
+ emoji: '⚡'
4
+ colorFrom: 'blue'
5
+ colorTo: 'purple'
6
+ sdk: 'gradio'
7
+ sdk_version: '3.40.1'
8
+ app_file: 'app.py'
9
+ pinned: false
10
+ license: 'mit'
11
+ tags:
12
+ - machine-learning
13
+ - regression
14
+ - electricity
15
+ - consumption
16
+ - prediction
17
+ - gradio
18
+ datasets:
19
+ - synthetic-electricity-data
20
+ metrics:
21
+ - mse
22
+ - rmse
23
+ - mae
24
+ - r2
25
+ ---
26
+
27
+ # ⚡ Electricity Consumption Predictor
28
+
29
+ A machine learning application that predicts daily electricity consumption based on various factors like temperature, day of the week, and special events.
30
+
31
+ ## 🚀 Live Demo
32
+
33
+ [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/surahj/electricity-consumption-predictor)
34
+
35
+ ## 📊 Features
36
+
37
+ - **Temperature-based predictions**: Considers how temperature affects electricity usage
38
+ - **Day of week analysis**: Accounts for different consumption patterns on weekdays vs weekends
39
+ - **Special events**: Factors in holidays and major events
40
+ - **Interactive interface**: User-friendly Gradio web interface
41
+ - **Model insights**: Detailed explanation of prediction factors
42
+
43
+ ## 🛠️ Technology Stack
44
+
45
+ - **Machine Learning**: scikit-learn (Linear Regression)
46
+ - **Data Processing**: pandas, numpy
47
+ - **Web Interface**: Gradio
48
+ - **Model Persistence**: joblib
49
 
50
  ## 🏗️ Project Structure
51
 
52
  ```
 
53
  ├── src/
54
+ │ ├── app.py # Main Gradio application
55
+ │ ├── model.py # ML model implementation
56
+ └── data_generator.py # Synthetic data generation
 
57
  ├── tests/
58
+ │ ├── test_model.py # Model unit tests
59
+ │ ├── test_app.py # App unit tests
60
+ └── test_integration.py # Integration tests
61
+ ├── app.py # Hugging Face Spaces entry point
62
+ ├── requirements.txt # Python dependencies
63
+ └── README.md # This file
 
 
 
64
  ```
65
 
66
+ ## 🧪 Usage
 
 
67
 
68
+ ### Local Development
 
69
 
70
+ 1. **Clone the repository**:
 
 
71
 
72
  ```bash
73
+ git clone https://github.com/YOUR_USERNAME/electricity-consumption-predictor.git
74
+ cd electricity-consumption-predictor
75
  ```
76
 
77
  2. **Install dependencies**:
 
83
  3. **Run the application**:
84
 
85
  ```bash
86
+ python app.py
87
  ```
88
 
89
+ 4. **Run tests**:
90
+ ```bash
91
+ pytest tests/
92
+ ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
+ ### Hugging Face Spaces
 
 
 
 
 
 
95
 
96
+ The app is automatically deployed on Hugging Face Spaces. Simply visit the live demo link above to use the application.
97
 
98
+ ## 📈 How It Works
 
 
 
 
 
 
99
 
100
+ 1. **Data Generation**: Creates synthetic electricity consumption data with realistic patterns
101
+ 2. **Model Training**: Trains a linear regression model on historical data
102
+ 3. **Feature Engineering**: Extracts relevant features (temperature, day of week, events)
103
+ 4. **Prediction**: Uses the trained model to predict consumption for new scenarios
104
+ 5. **Interpretation**: Provides detailed breakdown of prediction factors
105
 
106
+ ## 🎯 Model Features
 
 
107
 
108
+ - **Temperature Effect**: Higher temperatures increase AC usage
109
+ - **Day of Week**: Weekends typically have different consumption patterns
110
+ - **Base Consumption**: Minimum daily electricity usage
111
+ - **Event Impact**: Special events can significantly affect consumption
112
 
113
+ ## 📊 Example Predictions
114
 
115
+ | Temperature | Day | Event | Predicted Consumption |
116
+ | ----------- | --------- | ------- | --------------------- |
117
+ | 25°C | Monday | None | 16.5 kWh |
118
+ | 35°C | Saturday | Holiday | 22.3 kWh |
119
+ | 15°C | Wednesday | None | 14.1 kWh |
120
 
121
+ ## 🔧 Configuration
 
 
 
122
 
123
+ The model can be customized by modifying parameters in `src/model.py`:
124
 
125
+ - Training data size
126
+ - Feature weights
127
+ - Model hyperparameters
 
 
128
 
129
+ ## 🧪 Testing
130
 
131
+ Run the test suite to ensure everything works correctly:
132
 
133
  ```bash
134
+ # Run all tests
135
+ pytest tests/
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
+ # Run with coverage
138
+ pytest tests/ --cov=src
139
 
140
+ # Run specific test file
141
+ pytest tests/test_model.py
142
  ```
143
 
144
+ ## 📝 License
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146
+ This project is licensed under the MIT License - see the LICENSE file for details.
 
 
 
 
 
147
 
148
  ## 🤝 Contributing
149
 
 
151
  2. Create a feature branch
152
  3. Make your changes
153
  4. Add tests for new functionality
154
+ 5. Submit a pull request
 
155
 
156
+ ## 📞 Support
157
 
158
+ If you encounter any issues or have questions:
159
+
160
+ - Open an issue on GitHub
161
+ - Check the Hugging Face Spaces discussion
162
+ - Review the test files for usage examples
163
 
164
+ ---
165
 
166
+ **Built with ❤️ using Gradio and scikit-learn**