Bearing fault detection project: classify CWRU vibration data with Python

One complete machine learning project on the Case Western Reserve University bearing data, run end to end by Skill-Lync: the physics of a bearing fault, envelope analysis, the validation trap behind most 99% results, honest test numbers and the full code.

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

What is a bearing fault detection project?

It is a model that listens to a machine's vibration and says whether a rolling bearing is healthy or damaged, and where: inner race, outer race or ball. Each defect hits the balls at its own rhythm, so the job is to find that rhythm in a noisy signal. Think of it as a stethoscope that knows which knock means which part.

On the CWRU drive-end data, a random forest on six vibration features scored 99.1% with the split most tutorials use. Tested on bearings it had never seen, the same model scored 78.1%. Both numbers are real. Only the second one tells you how the model would do on a new machine, and the gap is the most useful lesson in this project.

99.1%random split (leaky)
78.1%on unseen bearings (honest)
1,146segments of 0.341 s from 40 recordings

What is in the CWRU bearing dataset?

Vibration recordings from a 2 hp electric motor whose drive-end bearing (an SKF 6205-2RS deep groove ball bearing) had a single pit cut into it by electro-discharge machining. Accelerometers on the motor housing recorded about 10 seconds per test at 12,000 samples per second, at four motor loads from 0 to 3 hp.

We used the standard 12 kHz drive-end set: three fault locations (inner race, ball, outer race at 6 o'clock) times three fault diameters (0.007, 0.014 and 0.021 inch, all 0.011 inch deep) times four loads, plus the four normal recordings. That is 40 files. The shaft runs at about 1797, 1772, 1750, 1730 rpm at 0, 1, 2 and 3 hp.

ClassFault sizes (inch)CWRU file numbersSegments
Normalnone97-100101
Inner race0.007, 0.014, 0.021105-108, 169-172, 209-212349
Ball0.007, 0.014, 0.021118-121, 185-188, 222-225348
Outer race (6 o'clock)0.007, 0.014, 0.021130-133, 197-200, 234-237348

Two traps in the files themselves. The normal recordings were sampled at 48,000 samples per second, not 12,000: they have four times as many samples for the same 10 seconds, and their spectral lines only land in the right place at 48 kHz. Resample them by 4 or the model learns "long file = healthy". And 99.mat also contains the variables from file 98, so pick the variable by file number, not by position.

Source: Case Western Reserve University Bearing Data Center (apparatus, bearing specifications, fault specifications and the 12k drive-end and normal baseline file tables, checked 17 Nov 2026). 1 mil = 0.001 inch, so the 7, 14 and 21 mil faults are 0.18, 0.36 and 0.53 mm across.

How does a damaged bearing show up in vibration?

Every time a ball rolls over a pit, it gives the housing a tiny hammer blow. The blows repeat at a rate set by the shaft speed and the bearing's geometry, different for the inner race, outer race and balls. So the fault is identified by how often the impacts repeat, not by how loud the machine is.

With n balls of diameter d on a pitch circle of diameter D, contact angle φ and shaft frequency fr:

The ball formula above counts both races: a pit on a ball strikes the inner and the outer race once per spin, which is why CWRU lists the rolling-element frequency as 4.7135 times shaft speed, twice the ball spin frequency. For the 6205 (9 balls, d = 0.3126 in, D = 1.537 in) these formulas give 5.4152, 3.5848, 4.7134 and 0.3983 times shaft speed, matching CWRU's table. At 0 hp:

Bearing defect frequency calculator
-Outer race, BPFO
-Inner race, BPFI
-Ball (2 × spin)
-Cage, FTF

Defaults: the CWRU drive-end bearing, SKF 6205-2RS (0.3126 in and 1.537 in converted to mm). Use your bearing's catalogue dimensions; real frequencies run 1-2% off the formula because the balls slip a little.

What is envelope analysis and why does it work?

The hammer blows ring the housing at a high natural frequency, thousands of hertz, so a plain spectrum shows the ringing, not the rhythm. Envelope analysis traces the outline of the signal (its envelope), which rises at each impact. The spectrum of that outline shows the impact rate directly: a peak at BPFO means an outer race fault.

Here 𝓗 is the Hilbert transform; in code it is one line, np.abs(hilbert(x)). The chart is the average envelope spectrum of each 0.34 s segment for the four 0 hp, 0.007-inch recordings, scaled so the median level is 1.

BPFOBallBPFI200Normal280Inner race320Outer race80Ball0 Hz100 Hz200 Hz300 Hz400 Hz
BPFO 107.4 HzBall 141.2 HzBPFI 162.2 Hzshaft 29.95 Hz

The inner and outer race faults are textbook: a sharp peak at their defect frequency, and for the outer race clear harmonics at 2× and 3×. The healthy bearing's biggest envelope line sits at 120 Hz, twice the 60 Hz US mains frequency: an electrical signature of the motor, not a bearing fault. The ball fault is the hard one. Its spectrum has no clear peak at 141.2 Hz, because a damaged ball keeps turning and only hits a race when the pit faces it. That is not a flaw of this code: Smith and Randall's benchmark study of the whole CWRU dataset (MSSP, 2015) also found many ball-fault recordings that standard diagnostic methods cannot identify.

Which features does the model use?

Six numbers per 0.34 s segment. Three describe the raw signal: RMS (overall vibration level), kurtosis (how spiky it is) and crest factor (peak over RMS). Three come from the envelope spectrum: the height of the biggest peak near BPFI, BPFO and the ball frequency, divided by the median level and logged.

The peaks are searched within ±4 Hz of each frequency at the recording's own shaft speed, because the speed drops by about 4% from 0 to 3 hp. With 4,096 samples at 12 kHz the frequency bins are 2.9 Hz wide, so ±4 Hz is a little over one bin either side.

The forest's importance scores: RMS (38%), Inner race peak (30%), Outer race peak (17%), Kurtosis (9%), Crest factor (5%), Ball peak (2%). Keep RMS at the top of that list in mind; it explains the result below.

Why do most CWRU projects report 99% accuracy?

Because they test on the same bearings they trained on. Cutting each recording into segments and splitting them at random puts neighbouring slices of one recording on both sides. Holding out a motor load is not enough either: CWRU ran the same damaged bearing at all four loads. Only holding out whole bearings, by fault size, gives an independent test.

Random 70/30 split of segmentsthe usual tutorial99.1%
Train 0-2 HP, test 3 HPsame bearings, new load96.9%
Test on unseen fault sizesnew bearings: the honest number78.1%
Envelope rule, no machine learningbiggest defect peak wins64.1%

For the honest split we trained on two fault sizes and tested on the third, three times over. Unseen 0.007-inch bearings: 95.0%. Unseen 0.021-inch: 86.2%. Unseen 0.014-inch: 53.1%, little better than a coin toss. The healthy bearing is a single unit, so its 3 hp recording is the test and the other three loads are training data in every fold.

This split was proposed by Hendriks, Dumond and Knox in "Towards better benchmarking using the CWRU bearing fault dataset" (Mechanical Systems and Signal Processing 169, 2022), who showed the motor-load split leaks for exactly this reason. The same mistake appears in tool-wear, gearbox and battery projects whenever several rows come from one physical part.

Where does the model go wrong?

It never misses the healthy bearing, and it mostly gets inner race faults right. Its big failure is the 0.014-inch outer race bearing: none of its 116 segments was called outer race; 108 were called "ball". The model leaned on how loud each training bearing was, and that bearing is far quieter than the others.

True ↓ / predicted →NormalInner raceOuter raceBallRecall
Normal87000100.0%
Inner race029005983.1%
Outer race8023110966.4%
Ball286227679.3%

Sum of the three unseen-fault-size folds; rows are the truth, columns the prediction. Normal appears in all three folds (its 3 hp recording, 29 segments each time).

On unseen 0.014-inch bearings, inner race recall was 57 of 116; the rest were called "ball". RMS being the top feature is the clue. Median RMS of the outer race segments was 0.587 and 0.566 for the 0.007 and 0.021 inch bearings, but only 0.096 for the 0.014-inch one, closer to the ball faults (0.116-0.144) and the healthy bearing (0.059). Train on the loud ones and "quiet" comes to mean "ball". Loudness depends on the exact pit, so it does not carry over between bearings. The envelope peaks are tied to the bearing geometry instead, which is why improving them (see the extensions below) helps more than a bigger model.

Is this the model or the luck of the draw? We re-ran both splits with five seeds. Random split: 97.7-99.1%. Unseen bearings: 76.9-79.1%. The gap is real.

And without machine learning? A plain rule, "call it the fault whose envelope peak is biggest, or Normal if every peak is under 2× the median", scores 64.1% on all segments with no training at all. It finds 100.0% of inner race segments but only 25.9% of ball faults and 38.6% of healthy ones. The forest earns its place by combining the peaks with the signal statistics.

The full Python code

About 60 lines of NumPy, SciPy and scikit-learn. Download the 40 files listed in FILES from the CWRU site into one folder, put the script next to them and run it. It prints the three accuracies and the confusion matrix in about 20 seconds on a laptop.

# Bearing fault classification on the CWRU drive-end data (12 kHz), run end to end.
# Put the 40 .mat files listed in FILES next to this script. Needs numpy, scipy, scikit-learn.
import numpy as np, scipy.io as sio
from scipy.signal import resample_poly, hilbert
from scipy.stats import kurtosis
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, confusion_matrix

FS, N = 12000, 4096                  # sampling rate (Hz), samples per segment (0.34 s)
RPM = [1797, 1772, 1750, 1730]       # nominal shaft speed at 0, 1, 2, 3 HP motor load
ORDERS = {"Inner race": 5.4152, "Outer race": 3.5848, "Ball": 4.7135}  # defect freq / shaft freq
CLASSES = ["Normal", *ORDERS]
FILES = {  # (class, fault size in mils): file number at load 0, 1, 2, 3 HP
    ("Normal", 0): [97, 98, 99, 100],
    ("Inner race", 7): [105, 106, 107, 108], ("Inner race", 14): [169, 170, 171, 172], ("Inner race", 21): [209, 210, 211, 212],
    ("Ball", 7): [118, 119, 120, 121], ("Ball", 14): [185, 186, 187, 188], ("Ball", 21): [222, 223, 224, 225],
    ("Outer race", 7): [130, 131, 132, 133], ("Outer race", 14): [197, 198, 199, 200], ("Outer race", 21): [234, 235, 236, 237],
}

def load(num):
    x = sio.loadmat(f"{num}.mat")[f"X{num:03d}_DE_time"].ravel()  # 99.mat also holds X098: pick by number
    return resample_poly(x, 1, 4) if num <= 100 else x               # the normal files are 48 kHz

def features(seg, rpm):
    rms = np.sqrt(np.mean(seg ** 2))
    env = np.abs(hilbert(seg - seg.mean()))                          # envelope: the impact rhythm
    spec = np.abs(np.fft.rfft(env - env.mean()))
    f = np.fft.rfftfreq(len(seg), 1 / FS)
    floor = np.median(spec[(f > 10) & (f < 500)])
    peaks = [spec[np.abs(f - o * rpm / 60) < 4].max() / floor for o in ORDERS.values()]
    return [rms, kurtosis(seg), np.abs(seg).max() / rms, *np.log(peaks)]

rows = []                                                            # one row per 0.34 s segment
for (cls, size), nums in FILES.items():
    for load_hp, num in enumerate(nums):
        x = load(num)
        for i in range(len(x) // N):
            rows.append((features(x[i * N:(i + 1) * N], RPM[load_hp]), CLASSES.index(cls), size, load_hp))
X = np.array([r[0] for r in rows]); y = np.array([r[1] for r in rows])
size = np.array([r[2] for r in rows]); load_hp = np.array([r[3] for r in rows])
print(f"{len(y)} segments, {X.shape[1]} features")

def fit_score(tr, te):
    rf = RandomForestClassifier(n_estimators=300, random_state=42).fit(X[tr], y[tr])
    pred = rf.predict(X[te])
    return accuracy_score(y[te], pred), confusion_matrix(y[te], pred, labels=range(4))

# 1. The usual tutorial split: random segments. Neighbouring slices of one recording land on both sides.
tr, te = train_test_split(np.arange(len(y)), test_size=0.3, stratify=y, random_state=42)
acc, _ = fit_score(tr, te); print(f"Random segment split:        {acc:.1%}")

# 2. Hold out a motor load: unseen 3 HP recordings, but the SAME damaged bearings as training.
acc, _ = fit_score(load_hp < 3, load_hp == 3); print(f"Train 0-2 HP, test 3 HP:     {acc:.1%}")

# 3. Hold out a fault size: bearings the model has never seen. The healthy bearing is a single
#    unit, so its 3 HP recording is held out and the other three loads are used for training.
cm_all = np.zeros((4, 4), int)
for s in (7, 14, 21):
    tr = ((size != s) & (y > 0)) | ((y == 0) & (load_hp < 3))
    te = ((size == s) & (y > 0)) | ((y == 0) & (load_hp == 3))
    acc, cm = fit_score(tr, te); cm_all += cm
    print(f"Test on unseen {s:2d}-mil bearings: {acc:.1%}")
print(f"Unseen-bearing accuracy, all three folds: {np.trace(cm_all) / cm_all.sum():.1%}")
print(cm_all)

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 files download from engineering.case.edu/sites/default/files/<number>.mat.

How do you make this project stand out?

Report the unseen-bearing number, not the 99%, and explain the gap. Then improve it with signal processing rather than a bigger model. Band-pass filtering before the envelope is the classic step: in our run, a 1-3 kHz band-pass lifted unseen-bearing accuracy from 78.1% to 83.1% with nothing else changed.

  • Choose the band properly. The 1-3 kHz band was one of a few we tried. Spectral kurtosis (the kurtogram) picks the band where the impacts are strongest, recording by recording.
  • Drop the loudness. Train once without RMS and crest factor and compare. A model that relies less on level should transfer better across bearings.
  • Add the hard cases. The 0.028 and 0.040 inch faults (NTN bearings, deeper pits) and the outer race at 3 and 12 o'clock test whether the model copes with a different load zone.
  • A second machine. Train on CWRU and test on another public bearing dataset, such as Paderborn University's, which includes real wear damage. Expect accuracy to drop, and write up why.

The honest limits of this project

The faults are machined, not worn. Each is one clean pit on a new bearing. Natural spalls grow, spread and change the signal over months, so CWRU is a fair test of the method but not of a production model.

Few physical bearings. Each class and size is one bearing. With three fault sizes, the honest test has only three folds, and one hard bearing (0.014 inch) moves the headline number by several points. Report per-fold results, as above.

One rig, one speed range. Every recording comes from the same motor at 1,720-1,800 rpm. A gearbox, a pump or a variable-speed drive would need the features recomputed at each instant's speed (order tracking).

What to learn to build projects like this

Python with NumPy and SciPy for signal handling, basic vibration theory, then classical machine learning: classification, random forests, cross-validation and model evaluation. That is the core of Skill-Lync's Machine Learning Fundamentals In Depth course (12 weeks). If you are new to coding, start with Python for Mechanical Engineers (4 weeks). Both are ₹40,000.

FAQs

Is the CWRU bearing dataset good for a final-year project?

Yes, if you test it honestly. The data is free, small (40 files of about 10 seconds each for the set used here) and runs on any laptop. Most published projects report 99% or more because they split segments of one recording into both training and test sets. Hold out whole fault sizes instead and explain what changes; that is what makes the project stand out.

Why do CWRU projects get 99-100% accuracy?

Because the test set is not independent. Each recording is cut into short segments, and a random split puts neighbouring segments of the same recording on both sides. Even holding out a motor load leaks, since CWRU reused the same damaged bearings at all four loads. In our run, accuracy fell from 99.1% to 78.1% once the test bearings were ones the model had never seen.

What are BPFO and BPFI?

Ball pass frequency outer and inner: how many times per second a ball rolls over a defect on the outer or inner race. They depend only on the shaft speed and the bearing geometry. For the CWRU drive-end bearing (SKF 6205-2RS) at 1797 rpm, BPFO is 107.4 Hz and BPFI is 162.2 Hz. Use the calculator on this page for any bearing.

Do I need deep learning for bearing fault diagnosis?

No. Six hand-made features and a random forest reached the accuracy shown here in a few seconds of training. Deep models (1D CNNs on raw vibration) are popular in papers, but they face the same leakage trap and are harder to explain to a maintenance engineer. Learn envelope analysis and honest validation first.

Is the CWRU data from real machines?

It is from a real test rig: a 2 hp motor with accelerometers on the housing. The faults are not natural wear, though. They are single pits cut into new bearings by electro-discharge machining, from 0.007 to 0.040 inch across. Real bearing damage grows gradually and spreads, so a model trained on CWRU alone should not go straight into a plant.

Get the syllabus and fee plans

Talk to a counsellor.

Tell us your branch and year. We'll send the syllabus for the 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.