This project leverages AI to monitor EV battery health, detect anomalies, and predict thermal risks, enabling safer and more efficient EV operation. It integrates tabular and sequence-based models to provide predictive insights on battery State of Health (SoH), motor/battery faults, and thermal anomalies.
Key Features:
- Detects motor and battery anomalies using autoencoders.
- Predicts battery SoH using Random Forest Regression.
- Identifies thermal runaway risks using LSTM Autoencoder.
- Generates sliding windows for AI models from raw telemetry.
- Provides a real-time control loop to decide charging mode: FAST, SLOW, or HOLD.
EV-Battery/
│
├─ data/
│ ├─ raw/
│ │ ├─ battery_bms_dataset.csv
│ │ ├─ motor_dataset.csv
│ │ └─ tele_dataset_.csv
│ └─ processed/
│ ├─ merged_enhanced.parquet
│ ├─ data_summary.csv
│ └─ windows/
│ ├─ windows_seq.npz
│ ├─ windows_tabular.npz
│ ├─ feature_cols.npy
│ ├─ window_starts.npy
│ └─ splits.joblib
│
├─ data_scripts/
│ ├─ 01_load_data.py # Load & clean datasets
│ └─ 02_make_windows.py # Create tabular & sequence windows
│
├─ training/
│ ├─ train_fault_encoder.py # Autoencoder for fault detection
│ ├─ train_soh_regressor.py # Random Forest for battery SoH
│ └─ train_thermal_autoencoder.py # LSTM for thermal anomaly detection
│
├─ inference/
│ └─ control_loop.py # Real-time inference & charging decision
│
├─ models/ # Trained model outputs
├─ requirements.txt
└─ README.md
- Install prerequisites:
python --version
git --version
pip install -r requirements.txt- Create and activate virtual environment (Windows):
python -m venv .venv
.venv\Scripts\activate-
VS Code extensions recommended: Python, Pylance, Jupyter, GitLens.
-
Test environment:
import numpy as np
print("Environment ready")- Input CSVs: battery, motor, telemetry.
- Merge, clean, and resample to 1-second intervals.
- Add engineered features like rolling stats, timestamp windows.
- Save outputs to Parquet and CSV for ML models.
Run:
python data_scripts/01_load_data.py- Generate tabular windows for Random Forest and autoencoder.
- Generate sequence windows for LSTM thermal model.
- Outputs saved to
data/processed/windows/.
Run:
python data_scripts/02_make_windows.pyExplanation: Sliding windows capture temporal patterns in battery and motor behavior for AI models.
| Task | Script | Model | Output |
|---|---|---|---|
| Fault Detection | train_fault_encoder.py |
Autoencoder | Detects anomalies & metrics |
| SoH Regression | train_soh_regressor.py |
Random Forest | Predicts battery SoH (%) |
| Thermal Anomaly Detection | train_thermal_autoencoder.py |
LSTM Autoencoder | Detects thermal anomalies |
- Learns normal battery/motor behavior.
- High reconstruction error → anomaly.
- Metrics: precision, recall, F1, AUC.
Run:
python training/train_fault_encoder.py- Predicts battery State of Health (SoH).
- SoH < 80% → battery unhealthy.
- Metrics: MAE, RMSE, R².
Run:
python training/train_soh_regressor.py- Detects potential overheating events.
- Uses sequence windows (temporal patterns).
- Threshold-based detection (95th percentile).
Run:
python training/train_thermal_autoencoder.pyScript: inference/control_loop.py
-
Loads tabular & sequence windows.
-
Loads trained models (SoH, fault, thermal).
-
Computes:
- Battery SoH prediction
- Fault reconstruction score
- Thermal anomaly probability
-
Decides charging mode:
- FAST: All checks healthy
- SLOW: Minor issues detected
- HOLD: Multiple issues detected
Run demo:
python inference/control_loop.pyExample Output:
⚡ Decision: SLOW | Reason: SoH low (74.3%), Fault detected (score=0.015)
-
Data Collection: EV battery, motor, and telemetry datasets.
-
Preprocessing & Feature Engineering: Cleaning, merging, rolling statistics.
-
Windowing: Tabular & sequence windows for model input.
-
Model Training:
- Fault detection → Autoencoder
- Battery health → Random Forest
- Thermal anomaly → LSTM Autoencoder
-
Evaluation & Thresholding: Metrics and 95th percentile anomaly thresholds.
-
Control Loop: Integrates model outputs to decide EV charging mode.
- ⚡ Safety: Detect faults and overheating early.
- 💰 Cost-saving: Prevent expensive EV failures.
- ⚙️ Scalable: Works across different EV datasets.
- 🔄 Flexible: Models can be retrained on new data easily.
| Model | Script | Purpose |
|---|---|---|
| Fault Autoencoder | train_fault_encoder.py |
Detect battery/motor anomalies |
| SoH Regressor | train_soh_regressor.py |
Predict battery State of Health |
| Thermal LSTM Autoencoder | train_thermal_autoencoder.py |
Detect thermal risks |
Absolutely! Using all the details you’ve provided so far (Task A, B, C, models, inference/control loop, methodology, team summary, outputs), I’ve drafted a full, detailed, professional README.md suitable for GitHub. I’ve structured it logically so anyone can follow from environment setup to running the full EV AI pipeline.
Here’s the complete version:
Team: AIML-TEAM 2 – Analyze, Predict, and Detect Anomalies
This project aims to predict the health of electric vehicle (EV) batteries, detect potential faults, and identify thermal anomalies using AI/ML models. It provides real-time decision support for charging and safety management.
Key functionalities include:
- Battery State-of-Health (SoH) Estimation – Predict whether the battery is healthy or degraded.
- Fault Detection – Detect motor or battery anomalies using Autoencoders.
- Thermal Anomaly Detection – Identify risk of overheating using LSTM Autoencoder.
- Control Loop / Charging Decision – Suggest safe charging modes (FAST, SLOW, HOLD) based on predictions.
The pipeline is divided into Tasks A, B, C, and D, forming a complete AI workflow for EV battery analysis:
-
Environment Setup
-
Install software: Python >=3.9, VS Code, Git
-
Initialize project folder and Git:
mkdir ev-aiml cd ev-aiml git init python -m venv .venv .venv\Scripts\activate pip install -r requirements.txt
-
Verify installations:
python --version git --version code --version
-
-
Data Preparation
-
Create
data/folder and upload datasets:battery_bms_dataset.csvmotor_dataset.csvtele_dataset_.csv
-
-
Load and Clean Data –
data_scripts/01_load_data.py-
Standardizes column names
-
Fills missing data
-
Adds timestamps
-
Resamples to 1-second intervals
-
Merges datasets into a single DataFrame
-
Generates advanced features: power, energy throughput, rolling statistics, temperature deltas, SoH normalization
-
Outputs:
data/processed/merged_enhanced.parquetdata/processed/data_summary.csv
-
Parquet Format: Optimized for ML pipelines; fast read/write, compressed, preserves column types.
Script: data_scripts/02_make_windows.py
-
Converts time-series data into fixed-length windows for ML models.
-
Outputs:
windows_seq.npz→ 3D array for sequence modelswindows_tabular.npz→ Aggregated features for tree modelsfeature_cols.npy→ List of numeric featureswindow_starts.npy→ Start timestampssplits.joblib→ Train/validation/test indicesscaler.joblib→ StandardScaler for features
Why Windowing: ML models require fixed-size inputs; EV battery anomalies depend on temporal patterns.
Script: training/train_fault_encoder.py
-
Trains an unsupervised Autoencoder on normal samples
-
Detects faults using reconstruction error
-
Outputs:
models/fault_autoencoder.kerasmodels/fault_autoencoder_metrics.joblib
Key Points:
- Encoder compresses input → bottleneck
- Decoder reconstructs input
- High reconstruction error → anomaly/fault
- Threshold-based anomaly detection using 95th percentile
Script: training/train_soh_regressor.py
-
Predicts battery health (% SoH)
-
Outputs:
models/soh_regressor.joblibmodels/soh_regressor_metrics.joblib
Interpretation:
- SoH < 80% → Battery considered unhealthy
- High accuracy on training/validation; low generalization on small test sets may occur
Script: training/train_thermal_autoencoder.py
-
Detects abnormal temperature patterns in battery/motor
-
Outputs:
models/thermal_autoencoder.kerasmodels/thermal_autoencoder_stats.joblib
Key Points:
- Sequence-to-sequence LSTM Autoencoder
- High reconstruction error → thermal anomaly
- 95th percentile threshold identifies risky windows
Script: inference/control_loop.py
-
Loads trained models & processed windows
-
Predicts SoH, fault score, thermal probability
-
Decides charging mode:
- FAST → Battery healthy
- SLOW → Minor issues
- HOLD → Multiple issues detected
Sample Output:
⚡ Decision: SLOW | Reason: SoH low (74.3%), Fault detected (score=0.015)
Custom Thresholds:
soh_thresh_low=0.75,fault_thresh=0.01,thermal_thresh=0.6- Adjustable for safer or more aggressive operation
| Member Name | Role | Responsibility |
|---|---|---|
| Shreelakshmi Hegde | AI/ML Developer | Data preprocessing, model training, SoH prediction |
| Akshay M | Backend Developer | Control loop, inference integration |
| Pratham | Data Engineer | Windowing, feature engineering |
- Clone Repository
git clone https://github.com/Shreelax21/EV-Battery.git
cd EV-Battery- Set Up Environment
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt- Preprocess Data
python data_scripts/01_load_data.py
python data_scripts/02_make_windows.py- Train Models
python training/train_fault_encoder.py
python training/train_soh_regressor.py
python training/train_thermal_autoencoder.py- Run Inference / Charging Decision
python inference/control_loop.py
``
---
**Conclusion**
This AI-based EV Battery Health & Fault Detection System provides a comprehensive solution for EV battery monitoring and safety management. By integrating fault detection, SoH prediction, and thermal anomaly identification, it ensures informed charging decisions, enhances vehicle safety, and reduces operational costs.
The modular, scalable design allows for retraining with new data, adaptation to different EV platforms, and continuous monitoring for performance optimization. This project highlights the critical role of AI in advancing electric vehicle reliability and efficiency.