Designed Vanilla RNN, LSTM and GRU models to predict the state of charge of a lithium-ion battery used in an EV.
The dataset contains data for driving trips that have been made using a BMW i3 EV. It has been originally sourced from IEEE Dataport, but published in Kaggle.
- Title: BATTERY AND HEATING DATA IN REAL DRIVING CYCLES
- URL: https://www.kaggle.com/datasets/atechnohazard/battery-and-heating-data-in-real-driving-cycles
| Generic Description of Dataset | |
|---|---|
| Number of trips | 70 |
| Number of categories | 2 |
| Number of trips in category A (summer) | 32 |
| Number of trips in category B (winter) | 38 |
| Total number of samples | 10,94,793 |
| Number of samples in category A | 4,67,701 |
| Number of samples in category B | 6,27,092 |
The training dataset has combined data from both categories, sorted in decreasing order of battery SoC.
| Generic Description of Training Dataset | |
|---|---|
| Number of trips | 35 |
| Number of trips in category A (summer) | 16 |
| Number of trips in category B (winter) | 19 |
| Total number of samples | 5,38,214 |
| Number of samples in training subset | 4,30,572 (80%) |
| Number of samples in validation subset | 1,07,642 (20%) |
| Input features | 3 (Battery Voltage, Battery Current,Battery Temperature) |
| Target variable | Battery SoC |
On the other hand, the test dataset contains data for 12 unseen trips, 6 each from category A and B. To normalize the training, validation and test datasets, min-max normalization has been used, with a scaling range of [-1, 1].
The SimpleRNN and Dense layers of the Sequential module of the Keras library in Python were used to implement the Vanilla RNN.
- The activation functions used are as follows:
- Tanh or hyperbolic tangent function for the hidden layer(s)
- Linear function for the output layer
- Mean squared error (MSE) was used as the loss function as well as a performance metric
- Along with MSE, R-squared (R2) score was used as a performance metric
- Stochastic gradient descent (SGD) with
0.025as the learning rate, was used as the optimizer
The optimal configuration for the Vanilla RNN model was determined using a trial and error approach, in which different configurations were trained for 100 epochs with 512 samples per batch, and their performance metrics were analysed. The configuration with the least possible MSE as well as highest possible R2 score was chosen as the optimal one.
The LSTM and Dense layers of the Sequential module of the Keras library in Python were used to implement the long short-term memory network. The activation functions, loss function, optimizer, learning rate and the performance metrics used are similar to the Vanilla RNN implementation, with the optimal configuration for the LSTM model also being determined in a similar fashion.
The GRU and Dense layers of the Sequential module of the Keras library in Python were used to implement the gated recurrent unit network. The activation functions, loss function, optimizer, learning rate and the performance metrics used are similar to the Vanilla RNN implementation, with the optimal configuration for the GRU model also being determined in a similar fashion.
The performance of the three optimal models was compared using the test datasets, as well as the remaining datasets that were not used for either training, validation or testing.
- Results for the Test Datasets
| Model | Number of Parameters | Overall Average MSE (in %) | Overall Average R2 Score (in %) |
|---|---|---|---|
| Vanilla RNN | 67,075 |
0.0587 |
99.9971 |
| LSTM | 2,67,523 |
0.0524 |
99.9958 |
| GRU | 2,01,475 |
0.0136 |
99.9992 |
- Results for the Miscellaneous Test Datasets
| Model | Number of Parameters | Overall Average MSE (in %) | Overall Average R2 Score (in %) |
|---|---|---|---|
| Vanilla RNN | 67,075 |
0.1622 |
99.9966 |
| LSTM | 2,67,523 |
0.1707 |
99.9961 |
| GRU | 2,01,475 |
0.0418 |
99.9991 |
In addition to the above RNN models, SoC prediction was carried out using some popular ML algorithms.
| Algorithm | Training R2 Score (in %) |
Validation R2 Score (in %) |
Test R2 Score (in %) |
Miscellaneous Test R2 Score (in %) |
|---|---|---|---|---|
| Linear Regression | 82.9611 |
82.8506 |
93.5213 |
81.5465 |
| Lasso Regression | 82.9510 |
82.8430 |
93.3572 |
81.3621 |
| Ridge Regression | 82.9575 |
82.8485 |
93.4173 |
81.4368 |
| Linear SVR | 81.9056 |
81.8045 |
94.5503 |
81.9790 |
| Decision Tree Regressor | 99.9899 |
96.5195 |
85.4748 |
71.3823 |
| AdaBoost Regressor | 74.1895 |
74.2081 |
77.1237 |
62.9671 |
| MLP Regressor | 92.8503 |
92.8617 |
94.7645 |
81.1827 |
| KNN Regressor | 98.7171 |
98.0798 |
84.5740 |
72.0371 |
| XGBoost Regressor | 96.8006 |
96.7200 |
90.1492 |
77.4607 |
| Random Forest Regressor | 99.7114 |
97.9454 |
89.2077 |
75.8618 |
| Gradient Boosting Regressor | 93.5534 |
93.4392 |
93.2566 |
79.7241 |
For the KNN Regressor, the best value of K was found by plotting the elbow curve for R2 scores versus different values of K.
The GRU model achieved the lowest MSE and highest R2 score of all the models tested and hence, it proved to be quite capable of accurately estimating the SoC of a battery operating under different conditions.