Battery remaining useful life project: predict Li-ion end of life from NASA aging data in Python

One complete project on NASA's Li-ion battery aging data, run end to end by Skill-Lync: how capacity fades, why it jumps back after a rest, two leaks that make tutorials look brilliant, state of health from charging data alone, a remaining-life forecast tested on cells the model never saw, and the full code.

By Skill-Lync · Published 24 Nov 2026 · Every number below was produced by the code on this page (scikit-learn 1.9.1, random_state 42)

What is a battery remaining useful life project?

It is a model that forecasts how many more charge-discharge cycles a battery can do before its capacity falls below an end-of-life line, here 1.4 Ah, 70% of the cell's rated 2 Ah. Think of it like reading a car tyre's tread depth every week and working out how many weeks it has left.

On NASA's four classic cells, a straight line through the last 20 cycles missed the end of life by 25.2 cycles on average. Matching the cell's current capacity against the other cells' histories missed by 8.1 cycles. Along the way, the feature many tutorials use for state of health turns out to be the capacity itself, read off a stopwatch.

8.1 cyclesmean RUL error on an unseen cell (matching method)
0.057 Ahstate-of-health error from charging data only, unseen cell
636discharge cycles across 4 cells

What is in the NASA battery data set?

Four 18650-size Li-ion cells cycled to death at NASA Ames in 2008. Each cycle is a charge at 1.5 A constant current to 4.2 V, then constant voltage until the current falls to 20 mA, and a discharge at 2 A until the voltage hits the cell's cut-off. Impedance sweeps from 0.1 Hz to 5 kHz were taken in between. Testing stopped at 30% capacity fade, from 2 Ah to 1.4 Ah.

CellCut-offDischargesFirst capacityLowestBelow 1.4 Ah at
B00052.7 V1681.856 Ah1.287 Ahcycle 125
B00062.5 V1682.035 Ah1.154 Ahcycle 109
B00072.2 V1681.891 Ah1.400 Ahnever
B00182.5 V1321.855 Ah1.341 Ahcycle 97

Three traps before you start. The cells are not new at cycle 1: B0005 and B0018 start at 1.856 and 1.855 Ah, 7% below the rated 2 Ah, B0007 at 1.891 Ah, and only B0006 starts above 2 Ah, so "state of health" depends on whether you divide by 2 Ah or by the first measurement. B0007 never drops below 1.4 Ah in its 168 discharges, so its true end of life is unknown (statisticians call that censored) and it cannot be scored for remaining life. And B0005, B0006 and B0007 were tested side by side from 2008-04-02 to 2008-05-27 with the same pauses, while B0018 ran alone from 2008-07-07 to 2008-08-20, so the first three are not fully independent samples.

The repository's battery zip holds 34 cells in nine batches, but the other batches are short (25 to 72 discharges for most), some never reach end of life, and the 4 °C batches' own READMEs warn of discharge runs with very low capacity whose reasons "have not been fully analyzed". That is why almost every study, and this project, uses these four.

Source: NASA Prognostics Center of Excellence data repository, "Battery Data Set" (B. Saha and K. Goebel, NASA Ames), file 1. BatteryAgingARC-FY08Q4.zip inside 5. Battery Data Set.zip, with README.txt (downloaded 24 Nov 2026). Test conditions above are quoted from that README.

How does a Li-ion cell's capacity fade?

Steadily, with bumps. Each cycle the cells lost a little capacity, and the loss sped up near the end. But every few dozen cycles the capacity jumped back up, then fell again within a few cycles. Those jumps line up with long pauses in the test.

1.21.41.61.82.004080120160Capacity (Ah)
B0005B0006B0007B00181.4 Ah end of lifex: discharge cycle

We counted every rise of more than 0.02 Ah from one discharge to the next. B0005 has 7, and the median rest before them was 32.7 hours, against 4.1 hours before an ordinary cycle. The longest pause, 310 hours before discharge 20, gave B0005 back 0.044 Ah. B0006 jumps the most (up to 0.152 Ah) and B0018 up to 0.131 Ah. This is capacity regeneration, usually put down to concentration gradients inside the cell relaxing during the rest. For a forecast it is noise that looks like a trend reversal.

Why does capacity fade at all? Mostly because lithium gets locked up in side reactions, like the film (the SEI layer) that keeps growing on the graphite anode, and because the electrodes slowly lose active material. The cell model behind state of charge and health is covered in our battery technology course.

Two leaks that make battery models look brilliant

The first is predicting next cycle's capacity from this cycle's: a rule that just copies the last value already scores an RMSE of 0.012 to 0.024 Ah on these cells. The second is using the time to peak temperature as a health feature: on a constant-current discharge it is the capacity, measured with a stopwatch.

Leak 1: one step ahead. Many tutorials train a network on the first part of a cell's capacity curve and report a tiny error predicting each next point. But capacity changes by about 0.01 Ah per cycle, so "next = current" is already that good. Any one-step-ahead result has to be compared with this copy-the-last-value baseline, and a real RUL forecast has to predict tens of cycles ahead with no future capacities fed back in.

Leak 2: time to peak temperature. The discharge runs at a constant 2 A, and the cell is hottest at the moment the load stops. So the time to peak temperature is the discharge time, and 2 A times the discharge time is the capacity. We checked: 2 A × time to peak temperature matched the recorded capacity to within 0.058 Ah on every one of the 636 discharges. A model on that one feature scores 0.016 Ah on an unseen cell, which looks superb and is useless in a car: to read it you must fully discharge the battery at constant current, which already tells you the capacity.

Can you estimate state of health from charging data alone?

Partly. An electric vehicle never discharges fully at constant current, but it does charge, often through the same constant-current then constant-voltage profile. As a cell ages, the constant-current part from 3.9 V to 4.2 V gets shorter and the constant-voltage taper gets longer. A linear model on those two times, trained on three cells and tested on the fourth, was off by 0.057 Ah on average.

Model (mean error, Ah)B0005 unseenB0006 unseenB0007 unseenB0018 unseenMean
Charge times only (CC 3.9-4.2 V, CV taper)0.0380.0760.0470.0670.057
Cycle number only (other cells' average)0.0280.0800.1020.0980.077
Time to peak temperature (the leak)0.0190.0080.0310.0070.016

Leave-one-cell-out: each column is a cell the model never saw in training. Capacity runs from about 2.0 to 1.15 Ah, so 0.057 Ah is about 3% of the rated 2 Ah.

The charge-only model beats counting cycles on average (0.057 against 0.077 Ah), mostly on the cells that aged unlike the others: B0007 and B0018. On B0005, the cycle count wins, because it aged like the average of the others. Now the contrast: a random forest on cycle number and both charge times, with the usual random 5-fold split, scores 0.011 Ah. It looks five times better only because neighbouring cycles of the same cell sit on both sides of the split.

Which remaining-life method works on an unseen cell?

Matching. At a given cycle, take the test cell's current capacity (averaged over 5 cycles), find when each of the other cells had that capacity, and read how many cycles each had left from there. The average was off by 8.1 cycles over 9 test points, against 25.2 for a straight line through the last 20 cycles and 50.1 for a line through every cycle so far.

Straight line through every cycle so farmisses the fade speeding up50.1 cyc
Straight line through the last 20 cyclesthrown off by capacity jumps after rests25.2 cyc
Match against the other cellswhere did a cell at this capacity end up?8.1 cyc

Mean absolute error in remaining cycles, B0005, B0006 and B0018 each forecast from cycles 40, 60 and 80; shorter is better.

Forecast fromTrue RULLine, all cyclesLine, last 20Matching
B0005, cycle 408537413374
B0006, cycle 4069694082
B0018, cycle 4057393950
B0005, cycle 60651578360
B0006, cycle 6049433958
B0018, cycle 60374710049
B0005, cycle 8045652738
B0006, cycle 8029131323
B0018, cycle 8017171020

Predicted remaining cycles; the closest forecast in each row is in bold. B0007 is left out because it never reached 1.4 Ah.

Read the rows. The line through every cycle predicts 374 cycles left for B0005 at cycle 40 (the truth is 85), because the early fade is slow and the line cannot know it will speed up. The last-20 line reacts faster but swallows the bumps: at cycle 60, B0018's window holds the jumps at cycles 46 and 56, after rests of 244 and 31 hours, the slope flattens, and it forecasts 100 cycles instead of 37.

Is it the choice of cycles 40, 60 and 80? Forecasting from every cycle from 20 up to end of life, the median error of matching was 5, 9 and 7 cycles for B0005, B0006 and B0018. The last-20 line had 16.6, 24.8 and 15.7. The all-cycles line was worst on B0005 (37.8) but best of the three on B0018 (5.9), so no method wins every cell. Matching wins on average.

Remaining-life explorer: forecast from any cycle
1.21.41.61.82.004080120160

Seen so farLast-20 lineMatching forecastTrue end of life

From cycle 60, B0005 had 65 cycles left.

Uses the page's own forecasts. The grey curve is the future the model cannot see.

The full Python code

About 100 lines of NumPy, SciPy and scikit-learn. Download the battery zip from NASA's repository, unzip it, unzip 1. BatteryAgingARC-FY08Q4.zip inside it, put the script next to the four .mat files and run it. It prints every number in this section's tables in a few seconds.

# Battery remaining useful life on NASA's Li-ion aging data (cells B0005, B0006, B0007, B0018).
# Put the four .mat files from "1. BatteryAgingARC-FY08Q4.zip" next to this script and run it.
import numpy as np, scipy.io as sio
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import KFold, cross_val_predict

CELLS = ["B0005", "B0006", "B0007", "B0018"]
EOL_AH = 1.4                      # end of life: 30% fade from the rated 2 Ah (README)

def load(cell):
    """One row per discharge: capacity (Ah), CC and CV time of the charge before it (s), time to peak temperature (s)."""
    rows, charge = [], None
    for c in sio.loadmat(f"{cell}.mat", simplify_cells=True)[cell]["cycle"]:
        d = c["data"]
        if c["type"] == "charge":
            charge = d
        elif c["type"] == "discharge":
            cc = cv = np.nan
            if charge is not None:
                t, v = np.asarray(charge["Time"]), np.asarray(charge["Voltage_measured"])
                if (v >= 4.199).any():
                    k42, k39 = np.argmax(v >= 4.199), np.argmax(v >= 3.9)
                    cc, cv = t[k42] - t[k39], t[-1] - t[k42]   # 3.9 -> 4.2 V at 1.5 A, then the CV taper
            td, temp = np.asarray(d["Time"]), np.asarray(d["Temperature_measured"])
            rows.append([float(d["Capacity"]), cc, cv, td[np.argmax(temp)]])
            charge = None
    return np.array(rows)

data = {c: load(c) for c in CELLS}
cap = {c: data[c][:, 0] for c in CELLS}
eol = {c: int(np.argmax(cap[c] < EOL_AH)) + 1 for c in CELLS if (cap[c] < EOL_AH).any()}
print("discharges:", {c: len(cap[c]) for c in CELLS}, "| end of life at cycle:", eol)

# 1. The one-step trap: "next cycle = this cycle" is the score any one-step-ahead model must beat
for c in CELLS:
    print(f"{c} persistence RMSE {np.sqrt(np.mean(np.diff(cap[c]) ** 2)):.4f} Ah")

# 2. Time to peak temperature is the capacity in disguise: the cell is hottest when the 2 A load stops
for c in CELLS:
    print(f"{c} max |2 A x t_peak - capacity| {np.max(np.abs(2 * data[c][:, 3] / 3600 - cap[c])):.3f} Ah")

# 3. State of health from the charge alone, tested on a cell the model has never seen
results = {}
def unseen_cell(cols, name):
    err = []
    for test in CELLS:
        tr = np.vstack([data[c] for c in CELLS if c != test]); te = data[test]
        tr, te = tr[~np.isnan(tr[:, cols]).any(1)], te[~np.isnan(te[:, cols]).any(1)]
        p = LinearRegression().fit(tr[:, cols], tr[:, 0]).predict(te[:, cols])
        err.append(np.abs(p - te[:, 0]).mean())
    results[name] = (err, float(np.mean(err)))
unseen_cell([1, 2], "charge_only")
unseen_cell([3], "temp_peak")
err = []                                   # baseline: the other cells' average capacity at the same cycle number
for test in CELLS:
    others = [cap[c] for c in CELLS if c != test]
    p = [np.mean([o[min(k, len(o) - 1)] for o in others]) for k in range(len(cap[test]))]
    err.append(np.abs(np.array(p) - cap[test]).mean())
results["cycle_only"] = (err, float(np.mean(err)))
X = np.vstack([np.column_stack([np.arange(len(cap[c])), data[c][:, 1:3]]) for c in CELLS])   # random split for contrast
y = np.concatenate([cap[c] for c in CELLS]); ok = ~np.isnan(X).any(1)
p = cross_val_predict(RandomForestRegressor(300, random_state=42), X[ok], y[ok], cv=KFold(5, shuffle=True, random_state=42))
results["random_split"] = (None, float(np.abs(p - y[ok]).mean()))
for k, (e, m) in results.items():
    print(f"SOH {k:12s} MAE {m:.3f} Ah" + ("" if e is None else "  per cell " + " ".join(f"{x:.3f}" for x in e)))

# 4. Remaining useful life from cycle k: straight lines vs matching the other cells
def rul_line(c, k, window):
    x = np.arange(1, k + 1)[-window:]; s, i = np.polyfit(x, cap[c][:k][-window:], 1)
    return (EOL_AH - i) / s - k if s < 0 else np.inf
def rul_fleet(c, k):
    now = cap[c][k - 5:k].mean(); guesses = []
    for o in eol:
        if o == c: continue
        smooth = np.convolve(cap[o], np.ones(5) / 5, "valid")
        m = int(np.argmax(smooth <= now)) + 5   # cycle at which cell o had the same capacity
        guesses.append(eol[o] - m)
    return float(np.mean(guesses))
rul = {"last20": [], "all": [], "fleet": []}
for k in (40, 60, 80):
    for c in eol:
        true = eol[c] - k
        pr = {"last20": rul_line(c, k, 20), "all": rul_line(c, k, k), "fleet": rul_fleet(c, k)}
        for m in rul: rul[m].append(abs(pr[m] - true))
        print(f"k={k} {c} true RUL {true:3d} | " + " ".join(f"{m} {pr[m]:.0f}" for m in pr))
for m in rul:
    print(f"RUL {m:6s} mean error {np.mean(rul[m]):.1f} cycles")

This is the same file we ran to produce the numbers on this page. Install with pip install numpy scipy scikit-learn (we used NumPy 2.5.5, SciPy 1.18.1, scikit-learn 1.9.1). The full zip is about 210 MB; the four cells used here are 56 MB of it.

How do you make this project stand out?

Report every result on a cell the model never saw, next to the dumb baselines: copy-the-last-value for one step ahead, cycle count for state of health, and matching for remaining life. A battery model that cannot beat them has not earned a place in a BMS, and saying so is what makes a reviewer trust the rest.

  • Use only part of the charge. Real drivers plug in at 30 or 40%. Recompute the constant-current time over a narrower window, say 4.0 to 4.1 V, and see how much accuracy you keep.
  • Add the impedance data. The files carry electrolyte resistance (Re) and charge-transfer resistance (Rct) from the sweeps. Do they track capacity on an unseen cell better than the charge times?
  • Give a range, not a number. Matching against two other cells gives two answers; report both, or fit a particle filter or Gaussian process and show the uncertainty band shrinking as the cell ages.
  • Model the rest effect. Add the hours of rest before each discharge as a feature and see whether it explains the jumps, or smooth them out before forecasting.

The honest limits of this project

Four cells, three with an end of life. Every remaining-life number here is an average over 9 forecasts from three cells, and matching uses only two reference cells each time. One unusual cell moves the result. Read the per-cell rows, not just the mean.

A lab cycle, not a car. Constant 2 A discharges at room temperature, back to back, are gentler and more regular than real driving, fast charging, heat and months parked. The method carries over; these error numbers do not.

Cells, not packs. A pack's life is set by its weakest cells, cell-to-cell spread and the cooling. Forecasting a pack needs per-cell or per-module data that this set does not have.

What to learn to build projects like this

Battery basics first: capacity, C-rate, state of charge, state of health and how CC-CV charging works. Then Python with NumPy for signal handling, and classical machine learning with grouped cross-validation. At Skill-Lync, the battery side is Introduction to Battery Technology for Electric Vehicle (12 weeks, ₹40,000), whose week 2 covers capacity, SOC, SOH and cycle life, and the ML side is Machine Learning Fundamentals In Depth (12 weeks, ₹40,000).

FAQs

What is the NASA battery data set?

Run-to-failure tests of 18650-size Li-ion cells at NASA Ames, published in NASA's prognostics data repository. The most used part is four cells, B0005, B0006, B0007 and B0018, charged at 1.5 A to 4.2 V and discharged at 2 A, over and over at room temperature, until their capacity fell 30% from the rated 2 Ah to 1.4 Ah. Each file records voltage, current and temperature for every charge and discharge, the capacity of every discharge and impedance sweeps.

What is the remaining useful life of a battery?

The number of charge-discharge cycles (or months of use) left before the battery reaches its end-of-life threshold, here 1.4 Ah, 70% of the rated capacity. Electric vehicle makers commonly use 70 to 80% as the point where a pack is too weak for the car, though it may still serve in stationary storage.

What is the difference between state of health and remaining useful life?

State of health (SOH) is where the battery is now: its capacity today compared with when it was new. Remaining useful life is where it is going: how many cycles until SOH hits the end-of-life line. You estimate SOH from today's signals, then forecast the RUL from how SOH has been falling. This project does both.

Is battery RUL prediction a good final-year project?

Yes, if you test it honestly. The data is free, the four cells are about 56 MB, and the whole project runs in seconds on a laptop. It mixes electric vehicle engineering with machine learning, and it has two traps you can explain in an interview: features that secretly contain the answer, and one-step-ahead scores that a copy-the-last-value rule matches.

Why does battery capacity go up after a rest?

It is called capacity regeneration. In this data, the clear jumps in capacity came after long pauses in testing: for B0005 the median rest before a jump of more than 0.02 Ah was 32.7 hours, against 4.1 hours before other cycles. It is usually put down to the cell's internal concentration gradients relaxing during the rest, and the extra capacity fades again within a few cycles. Any RUL model has to ride through these bumps.

Do I need an LSTM for battery RUL prediction?

Not to start. With four cells, any model learns from at most three of them. In our run, simply matching the test cell's capacity against the other cells' histories predicted end of life to within 8.1 cycles on average. Build that baseline first; a deep network has to beat it on a cell it has never seen to be worth the extra complexity.

Get the syllabus and fee plans

Talk to a counsellor.

Tell us your branch and year. We'll send the syllabus for the battery or machine learning course that fits and explain the payment plans.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.