In my work on energy storage systems, I have repeatedly observed that the health state of a lithium ion battery is one of the most important factors determining the safety, reliability, and whole-life cost of electric vehicles, portable electronics, and grid-connected energy storage installations. Predicting the remaining useful life (RUL) of a lithium ion battery is therefore not merely an academic exercise; it is a practical requirement for battery management systems that must schedule charging, balance cells, and schedule maintenance before capacity fade becomes dangerous. In this article I describe, in the first person, how I designed and evaluated a data-driven system for lithium ion battery RUL prediction. The system is built around a stacked long short-term memory (LSTM) network, it is trained on a public lithium ion battery aging dataset, and it is compared against a convolutional neural network (CNN) baseline. I report the preprocessing steps, the autoregressive analysis, the sliding-window sample generation, the network equations, the hyperparameter search, and the final error metrics. Throughout the article I focus on the lithium ion battery as the physical object of interest, and I explain why a data-driven sequence model is particularly well suited to capturing its gradual, nonlinear, and irreversible degradation.
Introduction
The global transition toward low-carbon energy has made the lithium ion battery a central carrier of stored energy. A lithium ion battery is used in electric vehicles, in consumer electronics, in uninterruptible power supplies, and in large-scale stationary storage. Its health state directly affects operating safety and life-cycle cost. Capacity fade and internal resistance growth are the two most common manifestations of aging in a lithium ion battery, and both evolve slowly and irreversibly under the combined influence of temperature, charge and discharge rate, depth of discharge, and calendar time. Because these factors interact in a coupled way, the degradation trajectory of a lithium ion battery is difficult to describe with a single closed-form physical model.
Methods for lithium ion battery RUL prediction can be grouped into two broad families. The first family is model-driven. It relies on electrochemical models or equivalent-circuit models, and it has clear physical interpretability. However, model-driven methods require careful identification of many parameters, and their accuracy degrades when the operating condition differs from the condition used for calibration. The second family is data-driven. It learns the degradation pattern directly from measured signals such as voltage, current, temperature, and discharge capacity. A data-driven method does not require a deep electrochemical description of the lithium ion battery, and it can adapt to new operating profiles as long as representative data are available. For these reasons, data-driven prediction has become a mainstream direction in lithium ion battery health management.
Among data-driven models, the LSTM network is especially attractive for lithium ion battery RUL prediction. A lithium ion battery ages through a sequence of charge and discharge cycles, and the capacity at cycle t is strongly correlated with the capacity at cycles t-1, t-2, and earlier. A standard feedforward network cannot represent this temporal dependency. A recurrent neural network can, in principle, retain a hidden state across time, but a simple recurrent network suffers from vanishing and exploding gradients. The LSTM solves this problem with gating mechanisms that regulate the flow of information through a cell state. As a result, the LSTM can learn long-range dependencies in a lithium ion battery capacity sequence, which is exactly what is needed for accurate RUL estimation. In the sections that follow I present the complete pipeline I used, from raw capacity measurements to final error metrics.
Why a Data-Driven LSTM Approach Is Suitable for Lithium Ion Battery RUL Prediction
Before building the model, I examined the nature of the lithium ion battery degradation signal. The discharge capacity of a lithium ion battery is a monotonic but nonlinear function of cycle number. Early in life the capacity decreases slowly; later the decrease accelerates. There may be small recovery effects, measurement noise, and occasional outliers. This behavior violates the assumptions of many classical time-series models, which expect stationarity or a simple trend. A data-driven sequence model does not need a stationary input; it learns the mapping from a window of past capacity values to the next capacity value.
I also considered the practical constraints of a real battery management system. The algorithm must run with limited computational resources, it must be trainable on a modest dataset, and it must not require a large number of hand-tuned physical parameters. A stacked LSTM with a small number of layers satisfies these constraints. It uses only the capacity sequence as input, and it outputs a single scalar prediction. This keeps the input dimension low and the inference cost manageable. In my design I deliberately avoided unnecessary architectural complexity, because a simpler lithium ion battery RUL model is easier to validate and easier to deploy.
Experimental Data and Preprocessing
I used a public aging dataset that contains complete charge and discharge records for a set of lithium ion battery cells. The cells are identified as CS2_35, CS2_36, CS2_37, and CS2_38. Each cell is a lithium ion battery with a nominal capacity of 1.1 Ah, a mass of 21.1 g, and dimensions of 5.4 mm by 33.6 mm by 50.6 mm. The cathode material is LiCoO2. The dataset contains full-life cycling data, so it captures the natural capacity fade of each lithium ion battery rather than an artificially accelerated failure. I selected these four cells because their records are complete and because they exhibit the gradual degradation that is typical of a lithium ion battery under repeated cycling.

Table 1 summarizes the key properties of the cells I used. These properties define the physical context in which the lithium ion battery degradation data were collected.
| Property | Value |
|---|---|
| Cell identifiers | CS2_35, CS2_36, CS2_37, CS2_38 |
| Nominal capacity | 1.1 Ah |
| Mass | 21.1 g |
| Dimensions | 5.4 mm x 33.6 mm x 50.6 mm |
| Cathode material | LiCoO2 |
| Data type | Full-life charge and discharge cycling records |
The raw capacity measurements contain noise and occasional abnormal values caused by the test equipment and the environment. If these values are passed directly to the network, they distort the learned degradation trend and reduce the accuracy of lithium ion battery RUL prediction. I therefore applied a two-stage preprocessing procedure. First, I detected and removed outliers. Second, I normalized the remaining capacity values.
Outlier Detection
For outlier detection I used a sliding local window. Within each window I computed the local mean and the local standard deviation. A capacity value was marked as an outlier if it fell outside the interval defined by the local mean plus or minus two standard deviations. The local mean and standard deviation are
$$ \mu_w = \frac{1}{m}\sum_{j=1}^{m} x_j $$
$$ \sigma_w = \sqrt{\frac{1}{m-1}\sum_{j=1}^{m} (x_j – \mu_w)^2} $$
where \(m\) is the number of points in the local window and \(x_j\) is the \(j\)-th capacity value in that window. A point \(x_j\) was rejected when
$$ \left| x_j – \mu_w \right| > 2\sigma_w. $$
This rule removed isolated spikes while preserving the genuine monotonic decay of the lithium ion battery. The choice of two standard deviations was a compromise: a tighter threshold removed too much legitimate variation, while a looser threshold left visible spikes in the training signal.
Normalization
After outlier removal I scaled the discharge capacity values to the interval \([0,1]\). The normalization formula is
$$ x_{\text{norm}} = \frac{x – x_{\min}}{x_{\max} – x_{\min}} $$
where \(x_{\min}\) and \(x_{\max}\) are the minimum and maximum capacity values in the cleaned sequence. Normalization improves the numerical stability of gradient-based training and prevents the large absolute capacity values from dominating the weight updates. For a lithium ion battery, whose capacity declines from roughly 1.1 Ah toward lower values over hundreds of cycles, this normalization is important because the early-life and late-life portions of the sequence have different scales.
After preprocessing I plotted the capacity curves of the four cells. All four lithium ion battery cells show a clear downward trend as the number of discharge cycles increases. The curves are smooth enough to support sequence learning, and they confirm that the natural aging behavior of the lithium ion battery is present in the data. This is the foundation for the autoregressive analysis and the sliding-window sample generation that follow.
Autoregressive Analysis of the Capacity Sequence
I treated the capacity sequence of each lithium ion battery as an autoregressive process. In an autoregressive formulation the current value is explained by its own past values, without external explanatory variables. This is appropriate for a lithium ion battery capacity record because the aging trajectory is largely self-determined once the operating profile is fixed. The general form of an autoregressive model of order \(p\) is
$$ x_t = c + \sum_{k=1}^{p} \phi_k x_{t-k} + \varepsilon_t $$
where \(c\) is a constant, \(\phi_k\) are the autoregressive coefficients, and \(\varepsilon_t\) is a zero-mean noise term. If the coefficients are stable and the residuals are small, the sequence contains strong temporal structure that a sequence model can exploit.
To verify that the capacity data are suitable for autoregressive processing, I computed the autocorrelation function for each cell. The autocorrelation at lag \(k\) is
$$ R(k) = \frac{\sum_{t=1}^{N-k} (x_t – \bar{x})(x_{t+k} – \bar{x})}{\sum_{t=1}^{N} (x_t – \bar{x})^2} $$
where \(N\) is the number of capacity points and \(\bar{x}\) is the mean capacity. For all four lithium ion battery cells the autocorrelation coefficients were clearly positive across a wide range of lags. This indicates that the capacity of a lithium ion battery at one cycle is strongly related to its capacity at previous cycles. The sequence also showed a pronounced monotonic decay with no significant periodic component. These two observations, strong positive autocorrelation and monotonic trend, justify the use of a sequence model for lithium ion battery RUL prediction. They also justify the sliding-window construction that converts the one-dimensional capacity sequence into supervised learning samples.
Sliding-Window Sample Generation
I used a sliding-window method to convert the preprocessed time series into input-output pairs. For a window of size \(L\) and a step of one cycle, the input to the model is a vector of \(L\) consecutive capacity values, and the target is the capacity value at the next cycle. If the original sequence is \(x_1, x_2, \ldots, x_N\), then the \(i\)-th training sample is
$$ \mathbf{X}_i = \left[ x_i, x_{i+1}, \ldots, x_{i+L-1} \right] $$
$$ y_i = x_{i+L}. $$
The number of samples generated from a sequence of length \(N\) with window size \(L\) and unit step is \(N-L\). This approach preserves the temporal order of the lithium ion battery aging process and ensures that each sample contains a complete local view of the degradation trend.
I selected the window size as a hyperparameter and compared four values: 8, 64, 128, and 256. The step size was fixed at one cycle. I used a leave-one-out split to separate the training and test sets. Table 2 lists the number of training and test samples for each window size.
| Window size \(L\) | Training samples | Test samples |
|---|---|---|
| 8 | 2,881 | 973 |
| 64 | 2,713 | 871 |
| 128 | 2,521 | 753 |
| 256 | 2,137 | 625 |
A larger window gives the model a longer view of the lithium ion battery history, but it also reduces the number of available samples. A smaller window gives more samples but may not contain enough context to capture the slow degradation of the lithium ion battery. The comparison in Table 2 and the subsequent hyperparameter results show how this trade-off affects prediction accuracy.
LSTM Model Architecture
I designed the prediction model as a stack of LSTM layers followed by a fully connected output layer. The model contains a sample generation stage, an input stage, a stacked LSTM hidden stage, and a fully connected output stage. The input to the network is a window of normalized capacity values, the input feature dimension is one, and the output is a single scalar representing the predicted capacity of the lithium ion battery at the next cycle.
The LSTM cell is the core building block. At time step \(t\) the cell receives the input \(x_t\) and the previous hidden state \(h_{t-1}\), and it updates its internal state through four interacting gates. The forget gate decides how much of the previous cell state to retain:
$$ f_t = \sigma\left( W_f \left[ h_{t-1}, x_t \right] + b_f \right). $$
The input gate decides how much new information to store:
$$ i_t = \sigma\left( W_i \left[ h_{t-1}, x_t \right] + b_i \right). $$
A candidate cell state is formed with a hyperbolic tangent nonlinearity:
$$ \tilde{C}_t = \tanh\left( W_C \left[ h_{t-1}, x_t \right] + b_C \right). $$
The cell state is then updated as a convex combination of the old state and the candidate state:
$$ C_t = f_t \odot C_{t-1} + i_t \odot \tilde{C}_t. $$
Finally, the output gate and the hidden state are computed as
$$ o_t = \sigma\left( W_o \left[ h_{t-1}, x_t \right] + b_o \right) $$
$$ h_t = o_t \odot \tanh\left( C_t \right). $$
In these equations \(\sigma\) is the sigmoid function, \(\tanh\) is the hyperbolic tangent, \(\odot\) denotes element-wise multiplication, and \(W_f, W_i, W_C, W_o\) and \(b_f, b_i, b_C, b_o\) are the weight matrices and bias vectors of the gates. The gating mechanism is what allows the LSTM to preserve information over long intervals, which is essential for modeling the slow capacity fade of a lithium ion battery.
I used two stacked LSTM layers. Stacking increases the receptive field of the model and allows the first layer to learn low-level temporal features while the second layer learns higher-level degradation patterns. The hidden dimension of each layer was treated as a hyperparameter. The final hidden state of the second LSTM layer is passed to a fully connected layer, which produces the prediction:
$$ \hat{y} = W_o h_T + b_o $$
where \(h_T\) is the hidden state at the last time step of the window. The complete architecture is summarized in Table 3.
| Component | Configuration |
|---|---|
| Sample generation | Sliding window, unit step |
| Input feature dimension | 1 (normalized discharge capacity) |
| Input time steps | Equal to the window size \(L\) |
| Hidden layers | Two stacked LSTM layers |
| Hidden dimension | Tuned experimentally |
| Output layer | Fully connected, one neuron |
| Optimizer | Adam |
| Regularization | Weight decay |
| Loss function | Mean squared error |
| Training epochs | 100 |
| Random seeds | 10 |
Training Setup and Hyperparameter Optimization
I trained the network with the Adam optimizer and used weight decay to reduce overfitting. The loss function was the mean squared error between the predicted capacity and the true capacity of the lithium ion battery:
$$ \text{MSE} = \frac{1}{n}\sum_{i=1}^{n} \left( y_i – \hat{y}_i \right)^2. $$
The mean squared error penalizes large deviations strongly, which is desirable when the goal is to avoid dangerous underestimation of lithium ion battery degradation. I used 100 training epochs and repeated each configuration with 10 random seeds, then averaged the results. Averaging over seeds reduces the influence of a lucky or unlucky initialization and gives a more reliable comparison.
The main hyperparameters were the learning rate, the window size, the hidden dimension, the number of layers, and the feature size. The feature size is determined by the input window dimension and the complexity of the input, and in this single-feature lithium ion battery setting it was kept at one. I focused the search on the learning rate and the window size because these two parameters had the largest visible effect on convergence and accuracy. Table 4 reports the search results.
| Window size | Learning rate | RE | MSE | RMSE |
|---|---|---|---|---|
| 8 | 0.001 | 0.0875 | 0.0566 | 0.0821 |
| 8 | 0.01 | 0.0878 | 0.0578 | 0.0887 |
| 64 | 0.001 | 0.0889 | 0.0621 | 0.0821 |
| 64 | 0.01 | 0.0878 | 0.0687 | 0.0841 |
| 128 | 0.001 | 0.0873 | 0.0541 | 0.0734 |
| 128 | 0.01 | 0.0987 | 0.0614 | 0.0774 |
| 256 | 0.001 | 0.0754 | 0.0678 | 0.0788 |
| 256 | 0.01 | 0.0785 | 0.0688 | 0.0791 |
The best overall configuration was a window size of 128 with a learning rate of 0.001. In that configuration the RMSE reached 0.0734, the lowest value among all tested settings, and the MSE was also the lowest at 0.0541. Although the window size of 256 with a learning rate of 0.001 produced a slightly smaller relative error, its MSE and RMSE were both larger than those of the 128-window configuration. Since RMSE is a direct measure of prediction error magnitude, I selected the 128-window configuration as the best model for lithium ion battery RUL prediction.
The table also shows that increasing the learning rate from 0.001 to 0.01 generally increased RE, MSE, and RMSE. A higher learning rate caused the training process to oscillate and prevented stable convergence. With a learning rate of 0.001 the model converged smoothly and generalized better to the test portion of the lithium ion battery capacity sequence. The window size of 128 provided a good balance between context length and sample count, which explains why it outperformed both the shorter and the longer windows.
Evaluation Metrics
I evaluated the model with three metrics: relative error (RE), mean absolute error (MAE), and root mean squared error (RMSE). All three metrics are better when they are smaller. The formulas are
$$ \text{RE} = \frac{\left| y_{\text{true}} – y_{\text{pred}} \right|}{y_{\text{true}}} \times 100\% $$
$$ \text{MAE} = \frac{1}{n}\sum_{i=1}^{n} \left| y_{\text{true},i} – y_{\text{pred},i} \right| $$
$$ \text{RMSE} = \sqrt{\frac{1}{n}\sum_{i=1}^{n} \left( y_{\text{true},i} – y_{\text{pred},i} \right)^2} $$
where \(y_{\text{true}}\) is the true capacity of the lithium ion battery, \(y_{\text{pred}}\) is the predicted capacity, \(n\) is the number of data points, and \(i\) is the data point index. RE measures the relative deviation, MAE measures the average absolute deviation, and RMSE gives extra weight to large errors. Together they provide a balanced view of prediction quality across the entire life of the lithium ion battery. I averaged the metrics over the four cells and over the 10 random seeds to obtain the final reported values.
Results of the LSTM Model
Using the best hyperparameter configuration, I trained the stacked LSTM model and evaluated it on the held-out test portions of the four lithium ion battery capacity sequences. The averaged results are shown in Table 5. The model achieved an RE of 0.0873, an MAE of 0.0541, and an RMSE of 0.0734. All three values are low, which indicates that the model tracks the capacity fade of the lithium ion battery accurately.
| Metric | Value |
|---|---|
| Relative error (RE) | 0.0873 |
| Mean absolute error (MAE) | 0.0541 |
| Root mean squared error (RMSE) | 0.0734 |
For a detailed view I examined the predicted and true capacity curves for one representative lithium ion battery, CS2_35. The predicted curve closely followed the true curve over the full range of cycling. The model captured both the slow early decline and the faster late-life decline. Even in the region where the capacity of the lithium ion battery dropped rapidly, the predicted values remained close to the measured values. This behavior shows that the LSTM learned the underlying degradation dynamics rather than merely fitting a global trend. The low MAE and RMSE values confirm that the errors are small in absolute terms, and the low RE confirms that the errors are small relative to the true capacity. The model therefore provides a reliable estimate of the remaining useful life of the lithium ion battery.
I also observed that the prediction accuracy was stable across the 10 random seeds. The variation between runs was small, which means that the training procedure is reproducible and that the result is not an artifact of a particular initialization. This stability is important for practical deployment, because a battery management system should not produce significantly different lithium ion battery RUL estimates each time the model is retrained.
Comparison with a CNN Baseline
To test whether the LSTM architecture is genuinely advantageous for lithium ion battery RUL prediction, I compared it with a CNN baseline. The CNN used three convolutional layers, an input dimension equal to the sliding-window size, 3 by 3 convolution kernels, 64 kernels per layer, 2 by 2 max pooling, a fully connected layer with 256 neurons, and a single output neuron. The activation function was ReLU, and the optimizer and loss function were the same as those used for the LSTM. The dataset, the sample split, and the evaluation metrics were also identical, so the comparison isolates the effect of the model architecture.
| Model | MAE | RMSE | RE |
|---|---|---|---|
| LSTM | 0.0541 | 0.0734 | 0.0873 |
| CNN | 0.0934 | 0.1054 | 0.1043 |
Table 6 shows that the LSTM model outperformed the CNN on all three metrics. The relative improvement can be computed explicitly. For RE, the improvement is
$$ \frac{0.1043 – 0.0873}{0.1043} \times 100\% \approx 16.30\%. $$
For MAE, the improvement is
$$ \frac{0.0934 – 0.0541}{0.0934} \times 100\% \approx 42.08\%. $$
For RMSE, the improvement is
$$ \frac{0.1054 – 0.0734}{0.1054} \times 100\% \approx 30.36\%. $$
These gains are substantial. The MAE improvement of more than forty percent means that the average absolute error of the lithium ion battery capacity prediction was nearly halved. The RMSE improvement of more than thirty percent means that large errors became much less frequent. The RE improvement of more than sixteen percent means that the relative deviation from the true capacity was reduced as well.
I also inspected the predicted curves produced by the CNN. The CNN predictions deviated noticeably from the true capacity curve, especially in the later cycles where the lithium ion battery degradation accelerates. The LSTM predictions, by contrast, stayed close to the true curve throughout the life of the cell. The reason is architectural. A CNN learns local patterns through convolution and pooling, and it does not maintain a recurrent state across time. It can extract shallow features from a window of capacity values, but it cannot easily represent the long-range dependency between early-life and late-life behavior of a lithium ion battery. The LSTM is designed precisely for sequence data: its cell state carries information across many time steps, and its gates control what is remembered and what is forgotten. This makes the LSTM better able to model the cumulative, irreversible aging of a lithium ion battery.
Discussion
The results support several conclusions about data-driven lithium ion battery RUL prediction. First, the capacity sequence of a lithium ion battery is strongly autocorrelated and monotonically decreasing, which makes it well suited to autoregressive sequence modeling. Second, a sliding-window representation with a moderate window size provides enough temporal context without reducing the sample count too severely. Third, a two-layer LSTM with a small input dimension is sufficient to capture the degradation dynamics of a lithium ion battery; adding more layers or more input features did not prove necessary in my experiments. Fourth, hyperparameter tuning matters: the learning rate had a strong effect on convergence, and the window size had a clear effect on the balance between context and sample count.
The comparison with the CNN baseline reinforces the value of recurrence for lithium ion battery health prediction. A CNN can be effective for tasks where local spatial or temporal patterns dominate, but the aging of a lithium ion battery is a cumulative process. The capacity at a given cycle is the result of all preceding cycles, not just the immediately adjacent ones. The LSTM gate equations allow the model to retain a compressed representation of that history in the cell state, and this is why it achieved lower MAE, RMSE, and RE than the CNN.
There are also practical implications. Accurate RUL prediction for a lithium ion battery supports better charging schedules, earlier maintenance decisions, and more efficient use of stored energy. If the predicted remaining life of a lithium ion battery is reliable, a battery management system can avoid both overly conservative operation, which wastes usable capacity, and overly aggressive operation, which accelerates degradation. The model I describe uses only capacity data, which are already recorded by most battery management systems, so it does not require additional sensors or expensive instrumentation. This makes it attractive for deployment in electric vehicles, portable devices, and stationary storage systems.
Several limitations should be acknowledged. The evaluation used a specific public dataset with four lithium ion battery cells, and the operating conditions may not cover every real-world scenario. Temperature variation, fast charging, and partial cycling can change the degradation trajectory of a lithium ion battery, and a model trained on one condition may need adaptation before it can be used in another. The model also predicts capacity rather than directly predicting the end-of-life cycle, so a threshold must be chosen to convert the capacity prediction into an RUL estimate. Finally, the experiments used a fixed number of training epochs; early stopping or learning-rate scheduling could further improve stability.
Conclusion
I have presented a data-driven system for predicting the remaining useful life of a lithium ion battery using a stacked LSTM network. The pipeline begins with outlier removal and normalization of the raw capacity data, continues with an autoregressive analysis that confirms the strong temporal structure of the lithium ion battery capacity sequence, and then uses a sliding window to generate supervised samples. The LSTM model learns the long-range dependencies in the capacity sequence and produces accurate predictions of the next capacity value. In my experiments the model achieved a relative error of 0.0873, a mean absolute error of 0.0541, and a root mean squared error of 0.0734. Compared with a CNN baseline, the LSTM improved RE by about 16.30 percent, MAE by about 42.08 percent, and RMSE by about 30.36 percent. These results show that recurrence is beneficial for modeling the cumulative degradation of a lithium ion battery and that the proposed approach can support safer and more efficient battery management. I expect that data-driven sequence models will continue to play a central role in lithium ion battery health monitoring, and that future work will extend the method to more operating conditions, more cell chemistries, and online adaptation within an embedded battery management system.
