|
--- |
|
license: mit |
|
tags: |
|
- regression |
|
- electricity |
|
- ev-charging |
|
- price-prediction |
|
- random-forest |
|
- scikit-learn |
|
- tabular-data |
|
language: |
|
- en |
|
library_name: scikit-learn |
|
datasets: |
|
- processed_electric_price_filled.csv |
|
metrics: |
|
- r2 |
|
- mse |
|
- mape |
|
model-index: |
|
- name: Electricity Price Predictor |
|
results: [] |
|
--- |
|
|
|
|
|
# π Electricity Price Predictor (Random Forest Regression) |
|
|
|
This is a custom regression model trained to predict electricity prices ($/kWh) in California, based on a variety of grid-level and environmental features such as EV charging demand, solar/wind production, carbon emissions, and storage indicators. |
|
|
|
The model is trained using `RandomForestRegressor` from `scikit-learn`, with 24 engineered features and a structured tabular dataset. This project is intended to support intelligent energy systems, such as EV charging optimization, energy scheduling, or smart grid simulation. |
|
|
|
--- |
|
|
|
## π Model Details |
|
|
|
- π **Model**: RandomForestRegressor (n_estimators=200) |
|
- π§ **Framework**: scikit-learn |
|
- π§Ύ **Input Features**: 24 numerical values (see full list below) |
|
- π― **Target Variable**: Electricity Price ($/kWh) |
|
- ποΈ **Data**: Structured time-series dataset with hourly EV/grid info |
|
- π§ͺ **Evaluation**: |
|
- MSE: *e.g., 0.0023* |
|
- RΒ²: *e.g., 0.89* |
|
- MAPE: *e.g., 6.5%* |
|
|
|
--- |
|
|
|
## π’ Input Features |
|
|
|
The model expects a list of 24 numeric features: |
|
|
|
```text |
|
['Year', 'Month', 'Day', 'DayOfWeek', 'Hour', |
|
'EV Charging Demand (kW)', 'Solar Energy Production (kW)', 'Wind Energy Production (kW)', |
|
'Battery Storage (kWh)', 'Charging Station Capacity (kW)', 'EV Charging Efficiency (%)', |
|
'Number of EVs Charging', 'Peak Demand (kW)', 'Renewable Energy Usage (%)', |
|
'Grid Stability Index', 'Carbon Emissions (kgCO2/kWh)', 'Power Outages (hours)', |
|
'Energy Savings ($)', 'Total_Renewable_Energy_Production', 'Effective_Charging_Capacity', |
|
'Adjusted_Charging_Demand', 'Net_Energy_Cost', 'Carbon_Footprint_Reduction', |
|
'Renewable_Energy_Efficiency'] |
|
|
|
``` |
|
--- |
|
--- |
|
|
|
## π§ͺ Usage Example |
|
|
|
### πΉ Option 1: Load and use the model directly |
|
|
|
```python |
|
import joblib |
|
import numpy as np |
|
|
|
# Load trained model |
|
model = joblib.load("random_forest_model.pkl") |
|
|
|
# Sample input (replace with actual values) |
|
features = [0.5] * 24 |
|
|
|
# Make prediction |
|
price = model.predict(np.array(features).reshape(1, -1))[0] |
|
print(f"Predicted Electricity Price: ${price:.4f}") |
|
``` |
|
|
|
--- |
|
|
|
### πΉ Option 2: Use helper function in `predict.py` |
|
|
|
```python |
|
from predict import predict |
|
|
|
features = [0.5] * 24 |
|
result = predict(features) |
|
print(f"Predicted Price: ${result:.4f}") |
|
``` |
|
|
|
--- |
|
|
|
### πΉ Option 3: Try it online (Gradio Web Demo) |
|
|
|
If deployed, you can try it here: |
|
[π Live Demo on Spaces](https://huggingface.co/spaces/YOUR_USERNAME/electricity-price-predictor-demo) |
|
|
|
--- |
|
|
|
## π Sample Dataset |
|
|
|
This repository includes a sample dataset: `processed_electric_price_filled.csv`. |
|
It contains hourly records of EV charging demand, solar/wind energy production, grid stability, and electricity prices. |
|
|
|
### Load and explore: |
|
|
|
```python |
|
import pandas as pd |
|
|
|
df = pd.read_csv("processed_electric_price_filled.csv") |
|
print(df.head()) |
|
``` |
|
|
|
--- |
|
|
|
## π Files Included |
|
|
|
| File | Description | |
|
|-------------------------------------|--------------------------------------------------| |
|
| `random_forest_model.pkl` | Trained RandomForestRegressor model | |
|
| `predict.py` | Python function to load and run predictions | |
|
| `app.py` (optional) | Gradio-based interactive demo | |
|
| `requirements.txt` | Python dependencies | |
|
| `processed_electric_price_filled.csv` | Training/test dataset | |
|
| `README.md` | This documentation | |
|
|
|
--- |
|
|
|
## π¨βπ» Author |
|
|
|
**bajiang(Georgia)** |
|
|
|
--- |
|
|
|
## π License |
|
|
|
MIT License β You are free to use, modify, and distribute this project with proper attribution. |