Beginner-friendly Python project for hourly energy consumption forecasting using a neural network (MLPRegressor), with a Flask API, a Streamlit dashboard, and a clear modular layout.
- Load CSV time series, resample to hourly frequency, and handle missing values
- Features: hour (0–23) and day of week (0–6, Monday=0)
- Train / test split (time-based), MAE, RMSE, R²
- Save the trained Pipeline (scaler + MLP) with joblib
- Plots saved under
images/ POST /predictAPI: JSON{"hour": int, "day": int}→ predicted energy
AI-Energy-Forecasting/
├── api/app.py # Flask API
├── dashboard/app.py # Streamlit UI
├── data/energy.csv # Dataset (generate sample below)
├── images/ # Figures from main.py
├── models/energy_model.pkl # Created after training
├── src/ # Core library modules
├── main.py # Full training pipeline
├── requirements.txt
└── scripts/generate_sample_data.py
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # macOS / Linux
pip install -r requirements.txtpython scripts/generate_sample_data.pyReplace data/energy.csv with your own file if you prefer. Expected columns:
timestamp— parseable datetimesenergy— numeric consumption
python main.pyThis writes:
models/energy_model.pklpredictions.csvmetrics.txtimages/*.png
From the project root:
python api/app.pyExample request:
curl -X POST http://127.0.0.1:5000/predict -H "Content-Type: application/json" -d "{\"hour\": 18, \"day\": 4}"streamlit run dashboard/app.py- Run API and Streamlit from the repository root so imports and paths resolve correctly.
- If you change the model file, restart the Streamlit app (or clear cache from the menu) so the new model loads.
MIT (adjust as needed for your course or organization).
Akanksha Andhale