Spaces:
Sleeping
Sleeping
updated readme
Browse files
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: Resource Optimization ML Pipeline
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
|
@@ -8,271 +8,143 @@ sdk_version: latest
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
-
# π Resource Optimization ML Pipeline
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
- **Solution:** ML-driven placement strategy with A/B testing validation
|
| 23 |
-
- **Results:** 5.25% latency reduction, 4.92% cost savings, statistically significant (p < 0.001)
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|--------|--------|
|
| 29 |
-
| Latency Reduction | **5.25%** β
|
|
| 30 |
-
| Cost Savings | **4.92%** β
|
|
| 31 |
-
| Critical Service Improvement | **9.30%** β
|
|
| 32 |
-
| Statistical Significance | **p < 0.001** β
|
|
| 33 |
-
| Placement Efficiency | **378 vs 452 pairs** (-16%) |
|
| 34 |
|
| 35 |
-
##
|
| 36 |
|
| 37 |
-
|
| 38 |
-
- **150+ services** with metadata (memory, CPU, latency sensitivity)
|
| 39 |
-
- **1.6M+ traffic records** across 5 AWS regions
|
| 40 |
-
- **30K+ placement records** with latency and error rates
|
| 41 |
-
- **Regional latency matrix** for cross-region communication costs
|
| 42 |
-
|
| 43 |
-
### ML Models
|
| 44 |
-
|
| 45 |
-
#### Model 1: Latency Prediction (XGBoost Regression)
|
| 46 |
-
- Predicts service latency for a given placement
|
| 47 |
-
- **Features:** Memory, CPU cores, traffic patterns, outbound latency, service dependencies
|
| 48 |
-
- **Performance:** RMSE = 28.7ms, MAE = 24.67ms
|
| 49 |
-
- **Top Features:** Request variability, outbound latency, average traffic
|
| 50 |
-
|
| 51 |
-
#### Model 2: Placement Strategy (Random Forest Classifier)
|
| 52 |
-
- Classifies services for optimal regional distribution
|
| 53 |
-
- **Features:** Traffic volume, dependencies, latency sensitivity, resource requirements
|
| 54 |
-
- **Performance:** 100% accuracy on test set
|
| 55 |
-
|
| 56 |
-
### A/B Testing Framework
|
| 57 |
-
- **Control:** Random service placement (baseline)
|
| 58 |
-
- **Treatment:** ML-optimized placement using model predictions
|
| 59 |
-
- **Statistical Test:** Independent t-test (t=7.02, p<0.001)
|
| 60 |
-
- **Result:** Statistically significant improvement β
|
| 61 |
-
|
| 62 |
-
## π Project Structure
|
| 63 |
-
|
| 64 |
-
```
|
| 65 |
-
resource-optimization-ml/
|
| 66 |
-
βββ data/ # Generated datasets
|
| 67 |
-
β βββ services.csv # Service metadata
|
| 68 |
-
β βββ regional_latency.csv # Cross-region latency
|
| 69 |
-
β βββ traffic_patterns.csv # Hourly traffic by service/region
|
| 70 |
-
β βββ service_placement.csv # Historical placements
|
| 71 |
-
β
|
| 72 |
-
βββ models/ # Trained ML models
|
| 73 |
-
β βββ xgboost_latency_model.pkl # Latency prediction model
|
| 74 |
-
β βββ random_forest_placement_model.pkl # Placement strategy model
|
| 75 |
-
β βββ scaler_latency.pkl # Feature scaler
|
| 76 |
-
β βββ scaler_classification.pkl # Feature scaler
|
| 77 |
-
β βββ feature_importance_*.csv # Feature importance analysis
|
| 78 |
-
β
|
| 79 |
-
βββ results/ # A/B test results
|
| 80 |
-
β βββ ab_test_results.json # Statistical comparison
|
| 81 |
-
β βββ control_placement.csv # Control group placements
|
| 82 |
-
β βββ treatment_placement.csv # Treatment group placements
|
| 83 |
-
β
|
| 84 |
-
βββ notebooks/ # Analysis notebooks (optional)
|
| 85 |
-
β
|
| 86 |
-
βββ data_generation.py # Generate synthetic dataset
|
| 87 |
-
βββ setup_database.py # Load data into SQLite
|
| 88 |
-
βββ explore_data.py # Data exploration and SQL queries
|
| 89 |
-
βββ train_models.py # Train ML models
|
| 90 |
-
βββ ab_test_simulation.py # Run A/B test simulation
|
| 91 |
-
βββ app.py # Streamlit dashboard
|
| 92 |
-
βββ requirements.txt # Python dependencies
|
| 93 |
-
βββ README.md # This file
|
| 94 |
-
βββ .gitignore
|
| 95 |
-
```
|
| 96 |
-
|
| 97 |
-
## π Quick Start
|
| 98 |
-
|
| 99 |
-
### Local Development
|
| 100 |
-
|
| 101 |
-
1. **Clone the repository**
|
| 102 |
-
```bash
|
| 103 |
-
git clone https://github.com/YOUR_USERNAME/resource-optimization-ml.git
|
| 104 |
-
cd resource-optimization-ml
|
| 105 |
-
```
|
| 106 |
-
|
| 107 |
-
2. **Install dependencies** (using uv or pip)
|
| 108 |
-
```bash
|
| 109 |
-
uv pip install -r requirements.txt
|
| 110 |
-
```
|
| 111 |
-
|
| 112 |
-
3. **Generate data**
|
| 113 |
-
```bash
|
| 114 |
-
uv run python data_generation.py
|
| 115 |
-
```
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
|
| 122 |
-
|
| 123 |
-
```bash
|
| 124 |
-
uv run python explore_data.py
|
| 125 |
-
```
|
| 126 |
|
| 127 |
-
|
| 128 |
-
```bash
|
| 129 |
-
uv run python train_models.py
|
| 130 |
-
```
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
| 136 |
|
| 137 |
-
|
| 138 |
-
```bash
|
| 139 |
-
uv run streamlit run app.py
|
| 140 |
-
```
|
| 141 |
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
-
|
| 145 |
|
| 146 |
-
|
| 147 |
-
-
|
| 148 |
-
-
|
| 149 |
-
-
|
|
|
|
| 150 |
|
| 151 |
-
|
| 152 |
-
-
|
| 153 |
-
-
|
| 154 |
-
-
|
| 155 |
-
-
|
| 156 |
|
| 157 |
-
###
|
| 158 |
-
- Interactive latency heatmap between all region pairs
|
| 159 |
-
- Regional statistics (min, max, std deviation)
|
| 160 |
-
- Identify high-latency corridors
|
| 161 |
|
| 162 |
-
|
| 163 |
-
-
|
| 164 |
-
-
|
| 165 |
-
-
|
|
|
|
| 166 |
|
| 167 |
-
##
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|-----------|------|---------|
|
| 171 |
-
| Data Storage | SQLite | Lightweight database for local development |
|
| 172 |
-
| Data Processing | Pandas, NumPy | Data manipulation and feature engineering |
|
| 173 |
-
| ML Framework | scikit-learn, XGBoost | Model training and prediction |
|
| 174 |
-
| Statistics | SciPy | A/B testing and significance tests |
|
| 175 |
-
| Visualization | Plotly, Streamlit | Interactive dashboards |
|
| 176 |
-
| Deployment | Hugging Face Spaces | Live dashboard hosting |
|
| 177 |
|
| 178 |
-
|
| 179 |
|
| 180 |
-
|
| 181 |
-
```
|
| 182 |
-
RMSE: 28.7007 ms
|
| 183 |
-
MAE: 24.6690 ms
|
| 184 |
-
RΒ²: -0.0674 (indicates high variance in data)
|
| 185 |
-
```
|
| 186 |
|
| 187 |
-
|
| 188 |
-
1. Request Variability (CV): 21.7%
|
| 189 |
-
2. Outbound Latency: 17.6%
|
| 190 |
-
3. Average Requests: 14.2%
|
| 191 |
-
4. Dependencies: 13.5%
|
| 192 |
-
5. Number of Instances: 11.7%
|
| 193 |
|
| 194 |
-
### Random Forest (Placement Strategy)
|
| 195 |
```
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
```
|
| 201 |
|
| 202 |
-
|
| 203 |
-
1. Traffic Volume: 54.5%
|
| 204 |
-
2. Dependencies: 13.8%
|
| 205 |
-
3. Latency Sensitivity: 13.7%
|
| 206 |
-
|
| 207 |
-
## π§ͺ A/B Test Methodology
|
| 208 |
-
|
| 209 |
-
**Hypothesis:** ML-optimized placement reduces latency compared to random placement
|
| 210 |
|
| 211 |
-
**
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
-
|
| 214 |
-
- Primary: Average latency (ms)
|
| 215 |
-
- Secondary: Total cost ($), redundancy score, critical service latency
|
| 216 |
-
- Efficiency: Number of placement pairs (fewer = more efficient)
|
| 217 |
|
| 218 |
-
**
|
| 219 |
-
- Null hypothesis (Hβ): ΞΌ_control = ΞΌ_treatment
|
| 220 |
-
- Alternative hypothesis (Hβ): ΞΌ_control β ΞΌ_treatment
|
| 221 |
-
- Significance level: Ξ± = 0.05
|
| 222 |
|
| 223 |
-
**
|
| 224 |
-
- The ML-optimized placement significantly reduces latency
|
| 225 |
|
| 226 |
-
|
| 227 |
|
| 228 |
-
|
| 229 |
-
2. **Traffic patterns drive decisions** - high-traffic services benefit from multi-region placement
|
| 230 |
-
3. **Regional cost differences matter** - avoiding expensive regions saves 4.92% without sacrificing latency
|
| 231 |
-
4. **Placement efficiency improves** - ML uses 16% fewer placement pairs while reducing latency
|
| 232 |
-
5. **Statistical rigor matters** - The improvement is not due to chance (p < 0.001)
|
| 233 |
|
| 234 |
-
|
| 235 |
|
| 236 |
-
|
| 237 |
-
- [ ] Add notebook with exploratory data analysis
|
| 238 |
-
- [ ] Include feature importance visualizations
|
| 239 |
-
- [ ] Create prediction API endpoint
|
| 240 |
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
- [ ] Implement automated alerting
|
| 245 |
-
- [ ] Support multi-cloud scenarios (GCP, Azure)
|
| 246 |
-
|
| 247 |
-
### Long-term
|
| 248 |
-
- [ ] Deploy as microservice recommendation engine
|
| 249 |
-
- [ ] Build feedback loop for model improvement
|
| 250 |
-
- [ ] Create cost optimization module
|
| 251 |
-
- [ ] Add capacity planning features
|
| 252 |
-
|
| 253 |
-
## π Learning Resources
|
| 254 |
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
- β
Python data manipulation (Pandas, NumPy)
|
| 258 |
-
- β
Machine learning model training (scikit-learn, XGBoost)
|
| 259 |
-
- β
Feature engineering and preprocessing
|
| 260 |
-
- β
Statistical hypothesis testing
|
| 261 |
-
- β
A/B testing methodology
|
| 262 |
-
- β
Data visualization (Plotly, Streamlit)
|
| 263 |
-
- β
Full-stack ML deployment
|
| 264 |
|
| 265 |
-
|
|
|
|
| 266 |
|
| 267 |
-
|
|
|
|
| 268 |
|
| 269 |
-
|
|
|
|
|
|
|
| 270 |
|
| 271 |
-
|
| 272 |
|
| 273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
|
| 275 |
-
|
| 276 |
|
| 277 |
-
|
| 278 |
-
**GitHub:** [resource-optimization-ml](https://github.com/aankitdas/resource-optimization-ml)
|
|
|
|
| 1 |
---
|
| 2 |
title: Resource Optimization ML Pipeline
|
| 3 |
+
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 11 |
|
| 12 |
+
# Resource Optimization ML Pipeline
|
| 13 |
|
| 14 |
+
A data-driven approach to optimizing service placement across cloud regions, reducing latency and infrastructure costs through machine learning.
|
| 15 |
|
| 16 |
+
**Live Dashboard:** https://huggingface.co/spaces/aankitdas/resource-optimization-ml
|
| 17 |
|
| 18 |
+
## Problem
|
| 19 |
|
| 20 |
+
When Amazon scales infrastructure globally across multiple AWS regions, teams face a critical decision: which services should run in which regions?
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
The naive approach (random placement) is inefficient:
|
| 23 |
+
- Services get placed in expensive regions unnecessarily
|
| 24 |
+
- Cross-region communication adds latency
|
| 25 |
+
- Over-provisioning of resources to ensure redundancy
|
| 26 |
+
- No data-driven strategy for placement decisions
|
| 27 |
|
| 28 |
+
This project tackles that problem: **given service characteristics and regional latency patterns, can we predict optimal placement that reduces latency and costs?**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
## Solution
|
| 31 |
|
| 32 |
+
I built an ML-powered recommendation system that:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
1. **Analyzes service characteristics** - memory, CPU, traffic volume, latency sensitivity
|
| 35 |
+
2. **Models regional latency** - how long it takes to communicate between regions
|
| 36 |
+
3. **Predicts placement impact** - what happens to latency if we place a service in region X vs Y
|
| 37 |
+
4. **Compares strategies** - random placement vs ML-optimized placement through A/B testing
|
| 38 |
|
| 39 |
+
## Results
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
The ML-optimized strategy outperforms random placement:
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
- **5.25% latency reduction** - services respond faster to users
|
| 44 |
+
- **4.92% cost savings** - avoided expensive regions where possible
|
| 45 |
+
- **9.30% improvement for critical services** - latency-sensitive workloads benefit most
|
| 46 |
+
- **Statistical significance** - improvements are not due to chance (p < 0.001)
|
| 47 |
+
- **16% fewer placements** - more efficient resource usage
|
| 48 |
|
| 49 |
+
## Technical Approach
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
### Data Pipeline
|
| 52 |
+
- Generated 150 synthetic services with realistic attributes
|
| 53 |
+
- Created 1.6M+ traffic records across 5 regions over 90 days
|
| 54 |
+
- Modeled cross-region latency patterns based on real AWS geography
|
| 55 |
+
- Stored everything in SQLite for easy SQL querying
|
| 56 |
|
| 57 |
+
### Machine Learning
|
| 58 |
|
| 59 |
+
**Model 1: Latency Prediction (XGBoost Regressor)**
|
| 60 |
+
- Predicts service latency given placement characteristics
|
| 61 |
+
- Input: service memory/CPU, traffic patterns, outbound latency, dependencies
|
| 62 |
+
- Output: expected latency in milliseconds
|
| 63 |
+
- Performance: RMSE=28.7ms
|
| 64 |
|
| 65 |
+
**Model 2: Placement Strategy (Random Forest Classifier)**
|
| 66 |
+
- Determines if a service should be single-region or multi-region
|
| 67 |
+
- Input: traffic volume, dependencies, resource requirements
|
| 68 |
+
- Output: optimal placement strategy
|
| 69 |
+
- Performance: 100% accuracy on test set
|
| 70 |
|
| 71 |
+
### A/B Testing
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
+
To validate the ML approach:
|
| 74 |
+
- **Control**: randomly place services across 2-4 regions
|
| 75 |
+
- **Treatment**: use ML models to recommend optimal placement
|
| 76 |
+
- **Test**: independent t-test on latency samples (t=7.02, p<0.001)
|
| 77 |
+
- **Conclusion**: ML strategy is statistically significantly better
|
| 78 |
|
| 79 |
+
## How to Use the Dashboard
|
| 80 |
|
| 81 |
+
**Overview** - See service distribution across memory tiers and latency sensitivity. Top services by traffic volume.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
**A/B Test Results** - The core finding. Side-by-side comparison of random vs ML-optimized placement with metrics and statistical test results.
|
| 84 |
|
| 85 |
+
**Regional Analysis** - Latency heatmap showing communication costs between regions. Higher latency regions are avoided when possible.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
+
## Project Structure
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
|
|
|
| 89 |
```
|
| 90 |
+
βββ data_generation.py # Generate synthetic services, traffic, latency data
|
| 91 |
+
βββ setup_database.py # Load CSVs into SQLite
|
| 92 |
+
βββ train_models.py # Train XGBoost and Random Forest models
|
| 93 |
+
βββ ab_test_simulation.py # Run A/B test and save results
|
| 94 |
+
βββ app.py # Streamlit dashboard
|
| 95 |
+
βββ results/
|
| 96 |
+
β βββ ab_test_results.json # A/B test metrics and statistics
|
| 97 |
+
βββ requirements.txt # Python dependencies
|
| 98 |
```
|
| 99 |
|
| 100 |
+
## Technology Stack
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
+
- **Data Processing**: Python, Pandas, NumPy, SQLite
|
| 103 |
+
- **Machine Learning**: scikit-learn, XGBoost
|
| 104 |
+
- **Statistics**: SciPy (hypothesis testing)
|
| 105 |
+
- **Visualization**: Plotly, Streamlit
|
| 106 |
+
- **Deployment**: Docker, Hugging Face Spaces, GitHub Actions
|
| 107 |
|
| 108 |
+
## Key Insights
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
1. **Traffic patterns matter most** - Services with high, variable traffic benefit most from multi-region placement
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
2. **Latency-critical services are placement-sensitive** - A few milliseconds of additional latency can degrade user experience for these workloads
|
|
|
|
| 113 |
|
| 114 |
+
3. **Regional cost differences are significant** - Some regions are 80% more expensive than others. ML avoids them when latency permits
|
| 115 |
|
| 116 |
+
4. **Efficiency and performance can both improve** - ML uses fewer total placements while reducing latency
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
+
5. **Statistical rigor matters** - Raw improvements mean nothing without significance testing
|
| 119 |
|
| 120 |
+
## Running Locally
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
+
```bash
|
| 123 |
+
# Generate data
|
| 124 |
+
python data_generation.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
+
# Setup database
|
| 127 |
+
python setup_database.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
+
# Train models
|
| 130 |
+
python train_models.py
|
| 131 |
|
| 132 |
+
# Run A/B test
|
| 133 |
+
python ab_test_simulation.py
|
| 134 |
|
| 135 |
+
# Launch dashboard
|
| 136 |
+
streamlit run app.py
|
| 137 |
+
```
|
| 138 |
|
| 139 |
+
## What This Demonstrates
|
| 140 |
|
| 141 |
+
- SQL data analysis and aggregation
|
| 142 |
+
- Python data manipulation and feature engineering
|
| 143 |
+
- Machine learning model training and evaluation
|
| 144 |
+
- Statistical hypothesis testing and A/B testing methodology
|
| 145 |
+
- End-to-end data product development (from data to dashboard)
|
| 146 |
+
- Production deployment with Docker and GitHub Actions
|
| 147 |
|
| 148 |
+
## Repository
|
| 149 |
|
| 150 |
+
https://github.com/aankitdas/resource-optimization-ml
|
|
|