End-to-end ML pipeline for SoC, SoH, and RUL prediction of lithium-ion batteries.
Battery Management Systems (BMS) need answers to three critical questions:
| # | Question | Technical Term | Our Model |
|---|---|---|---|
| 1 | "How much charge is left right now?" | State of Charge (SoC) | LSTM Neural Network |
| 2 | "How degraded is this battery?" | State of Health (SoH) | XGBoost (Gradient Boosting) |
| 3 | "How many cycles before it dies?" | Remaining Useful Life (RUL) | LSTM Neural Network |
This pipeline takes raw NASA battery cycling data β parses .mat files β engineers physics-informed features β trains 3 models β outputs evaluation metrics + publication-ready plots.
| Model | RMSE | MAE | RΒ² Score | Interpretation |
|---|---|---|---|---|
| SoC (LSTM) | 7.24% | 2.82% | 0.9499 | Excellent β explains 95% of variance |
| SoH (XGBoost) | 3.09% | 2.76% | 0.8260 | Good β captures degradation trend |
| RUL (LSTM) | 12.49 cycles | 9.21 cycles | 0.8699 | Good β average error ~9 cycles |
All 4 batteries show clear degradation over cycling. B0018 (4A discharge) degrades faster than B0005βB0007 (2A), consistent with Arrhenius kinetics.
The LSTM captures the full discharge curve trajectory. Predictions closely track the actual SoC with RΒ² = 0.95.
XGBoost tracks the overall degradation trend from 93% β 65% SoH. Feature importance reveals temperature variance (57%) and discharge time (29%) are the dominant aging indicators.
The LSTM learns the countdown pattern (120 β 0 cycles remaining). Error distribution is centered near zero, with most predictions within Β±10 cycles.
Both LSTM models converge smoothly with early stopping preventing overfitting.
NASA Prognostics Center of Excellence (PCoE) Battery Dataset β 4 Γ 18650 Li-ion cells cycled to failure.
| Battery | Discharge Rate | ~Cycles | EOL Reached? |
|---|---|---|---|
| B0005 | 2A | 168 | β |
| B0006 | 2A | 168 | β |
| B0007 | 2A | 168 | β |
| B0018 | 4A | 132 | β |
- Charge: CC-CV at 1.5A β 4.2V cutoff
- Discharge: Constant current until 2.7V
- EOL threshold: 70% of rated capacity (1.4 Ah out of 2.0 Ah)
- Source: NASA PCoE Repository
NASA .mat files
β scipy.io.loadmat
Parse MATLAB structs β Extract discharge cycles only
β Current integration: Q(t) = β«|I(Ο)|dΟ
Clean DataFrame (remove NaN/Inf)
β
βββ SoC Path: MinMax normalize β sliding window (50 steps) β LSTM
β
βββ Cycle Path: Aggregate 8 features per cycle
βββ SoH: XGBoost on tabular features
βββ RUL: Lookback window (10 cycles) β LSTM
| Feature | Formula | Physical Basis |
|---|---|---|
max_capacity |
NASA reported (Ah) | Direct health indicator |
discharge_time |
t_end β t_start | Shorter = degraded |
avg_voltage |
mean(V) | Drops with SEI growth |
voltage_drop |
V_max β V_min | Internal resistance proxy |
avg_current |
mean(|I|) | Operating condition |
avg_temperature |
mean(T) | Arrhenius aging factor |
temp_variance |
var(T) | Thermal instability |
internal_resistance |
ΞV / I_avg | Primary aging indicator |
| SoC (LSTM) | SoH (XGBoost) | RUL (LSTM) |
|---|---|---|
|
|
|
| Why LSTM? SoC depends on temporal voltage/current history β same voltage can mean different SoC depending on trajectory. | Why XGBoost? Only ~630 cycles of tabular data β trees outperform neural nets on small structured datasets. | Why LSTM? RUL requires detecting acceleration in degradation β the model needs to see trends over past cycles. |
- Chronological split (80/20) β prevents future data leakage (critical for time-series)
- MinMax scaling β bounded [0,1] range works better with LSTM's sigmoid/tanh activations
- Early stopping β prevents overfitting by monitoring validation loss
max_capacityexcluded from SoH features β avoids circular prediction (SoH is derived from capacity)
battery-diagnostics-NASA/
βββ data/
β βββ download_data.py # Auto-downloads from NASA S3
βββ src/
β βββ data_loader.py # .mat parsing + current integration
β βββ preprocessing.py # Clean, normalize, sliding windows
β βββ feature_engineering.py # 8 cycle features + SoH/RUL labels
β βββ evaluation.py # RMSE, MAE, RΒ² metrics
β βββ visualization.py # 6 publication-ready plots
β βββ models/
β βββ soc_model.py # LSTM for SoC
β βββ soh_model.py # XGBoost for SoH
β βββ rul_model.py # LSTM for RUL
βββ plots/ # Generated diagnostic plots
βββ results/ # Saved predictions & metrics (CSV/JSON)
βββ main.py # β Run this! End-to-end pipeline
βββ requirements.txt
# Clone
git clone https://github.com/ARYANRAJ1121/battery-diagnostics-NASA.git
cd battery-diagnostics-NASA
# Setup
python -m venv venv && venv\Scripts\activate # Windows
pip install -r requirements.txt
# Run entire pipeline (~5 min)
python main.pyOutput: Metrics printed to console + 6 plots in plots/ + 7 result files in results/
This project bridges data-driven ML and electrochemical domain knowledge:
| Degradation Mechanism | Feature That Captures It |
|---|---|
| SEI layer growth | internal_resistance β, avg_voltage β |
| Lithium inventory loss | max_capacity β, discharge_time β |
| Thermal aging (Arrhenius) | avg_temperature β, temp_variance β |
| Electrode cracking | voltage_drop β |
Relevant to: Battery Management Systems (BMS), Prognostics & Health Management (PHM), Electric Vehicle reliability, Grid-scale energy storage
- Transformer-based models (PatchTST) for longer-range dependencies
- Physics-Informed Neural Networks (PINNs) combining data + electrochemical equations
- Transfer learning across battery chemistries
- Uncertainty quantification (confidence intervals on predictions)
- B. Saha, K. Goebel (2007). "Battery Data Set", NASA Ames Prognostics Data Repository
- K. Severson et al. (2019). "Data-driven prediction of battery cycle life before capacity degradation", Nature Energy
- M. Berecibar et al. (2016). "Critical review of state of health estimation methods", Renewable & Sustainable Energy Reviews
- Y. Zhang et al. (2018). "LSTM RNN for remaining useful life prediction", Engineering Applications of AI
- T. Chen, C. Guestrin (2016). "XGBoost: A Scalable Tree Boosting System", KDD
MIT License β see LICENSE
Built for research internship application β IIT Jammu
Demonstrating proficiency in battery diagnostics, deep learning, and reproducible ML research





