Sitemap
Moomaleman

Moomaleman

Can a Straight Line Catch a Short Circuit? Detecting Transmission Line Faults with Logistic Regression and SVMs

7 min readOct 11, 2026

--

By Moomal Eman and Tayyba

When something goes wrong on a power line, like a phase touching the ground or two phases touching each other, the line currents shoot up and the voltages sag. A protective relay has to notice this within milliseconds and trip the breaker. If it doesn’t, transformers burn, lines get damaged and the grid can become unstable.

In this project we asked a simple-sounding question:

Can a straight-line decision boundary detect a fault from raw instantaneous measurements? If not, what is the simplest fix: changing the features, or changing the classifier?

We wrote logistic regression ourselves in NumPy and trained linear and RBF support vector machines with scikit-learn. The short answer is that a straight line fails badly, and both fixes work. The interesting part is why.

The data

We used the Electrical Fault Detection and Classification dataset from Kaggle. It comes from a MATLAB/Simulink simulation of a three-phase power system. Each of the 12,001 rows is one instant in time, with six measurements:

  • the three line currents Ia, Ib, Ic (in amps),
  • the three line voltages Va, Vb, Vc (in per unit),

and a label: 1 = fault, 0 = no fault.

The file had two completely empty columns at the end (Unnamed: 7 and Unnamed: 8), which we dropped. There were no other missing values. The classes are fairly balanced: 5,496 fault rows and 6,505 normal rows. We split the rows randomly with a fixed seed into 60% training, 20% validation and 20% test (7,200 / 2,400 / 2,401 rows), and standardised every feature using the training mean and standard deviation only.

What does a fault look like?

The first plot shows the three currents for the first 2,000 time samples, with the fault period shaded grey.

Press enter or click to view image in full size
Line currents for the first 2,000 samples. During the fault (shaded), Ia jumps from about ±60 A to about ±880 A.

Before the fault, the currents are neat sine waves of about ±60 A. As soon as the fault starts, Ia jumps to about ±880 A, roughly 14 times bigger, while Ib and Ic stay small. When the fault clears, everything goes back to normal.

Now here is the key plot. It shows every row as a point in the (Ia, Ib) plane, coloured by class:

Press enter or click to view image in full size
Ia vs Ib. Normal points (blue) sit in a small blob at the centre, and fault points (orange) surround it on every side, so no straight line can separate them.

The normal points (blue) form a small blob around the origin. The fault points (orange) form huge rings that go all the way around that blob. A fault doesn’t push the current in one direction. It makes the current big, and because it is still AC, “big” can be +800 A one moment and −800 A a few milliseconds later.

The histogram of Ia tells the same story: normal rows are packed between about −170 and +105 A, and fault rows are spread across −880 to +885 A, almost symmetric around zero.

So can a single straight line separate the two classes? No. A line splits the plane into two halves. It can’t put “the middle” on one side and “everything around the outside” on the other.

Attempt 1: logistic regression on the raw features

We implemented logistic regression from scratch: the sigmoid, the hypothesis h(x) = g(θᵀx), the log-likelihood cost J(θ), and batch gradient descent starting from θ = 0. As a sanity check, J(θ) starts at exactly log 2 ≈ 0.693, because with θ = 0 every prediction is 0.5.

To choose the learning rate α, we ran 2,000 iterations for α ∈ {0.01, 0.1, 1, 10} and picked the largest α for which the cost went down at every iteration. For the six raw features (we called this Set R), α = 10 made the cost jump around between 1.34 and 1.70, so we chose α = 1.

The result: 73.1% validation accuracy. That sounds okay until you look at the errors.

Fix 1: change the features

If the problem is that a fault means “far from zero in either direction”, then let’s give the model a feature that measures exactly that. Squaring does the job: Ia² is large whether Ia is +800 or −800.

So we built Set Q: the six raw features plus their six squares, with the squares computed from the raw values first and then everything standardised. Same model, same code, same gradient descent (this time α = 10 worked fine).

Get Moomaleman’s stories in your inbox

Join Medium for free to get updates from this writer.

The result: 97.8% validation accuracy. Nothing about the classifier changed. It is still a straight line, but now it’s a straight line in a space where faults and normal operation actually are on different sides.

The learned weights make physical sense:

Press enter or click to view image in full size
Learned Set Q weights: current-squared terms are positive (fault means large current), voltage-squared terms are negative (fault means voltage sag).

All current-squared weights are positive: a short circuit makes the current huge, so large I² pushes the prediction towards “fault”. All voltage-squared weights are negative: during a fault the voltage sags (in our data the average V² drops from about 0.18 to about 0.04–0.06), so a small V² means fault, and a large, healthy V² pushes the prediction away from it. The model rediscovered basic power-system physics on its own.

Fix 2: change the classifier

The other option is to keep the raw features and use a classifier that can draw curved boundaries. We trained SVMs on Set R:

  • linear SVM with C ∈ {0.1, 1, 10, 100},
  • RBF SVM with C ∈ {0.1, 1, 10, 100} and γ ∈ {0.1, 1}.
Press enter or click to view image in full size
Validation accuracy against C. The linear SVM is stuck at 72.6% for every C, while the RBF SVM climbs to 99.7%.

The linear SVM scored 72.6% for every value of C, almost identical to logistic regression on Set R. That is no coincidence. Both models draw a straight line, and they only differ in how they choose it (log-loss vs. maximum margin). If the best possible line only reaches about 73%, every linear model ends up there.

The RBF SVM, which can wrap a curved boundary around the normal blob, reached 99.7% with C = 100 and γ = 1.

The number of support vectors tells the same story. The linear SVM needed 5,846 support vectors, 81% of all training points. That means almost every point was inside the margin or on the wrong side, because the model simply couldn’t find a clean boundary. The best RBF SVM needed only 278 (about 4%).

We also saw a clear pattern as C increased: RBF accuracy went up and the number of support vectors went down (from 1,348 to 174 for γ = 0.1). C is the penalty for points that break the margin. Small C tolerates many violations (wide margin, many support vectors), and large C forces the boundary to fit the data more closely. For the linear SVM, C changed nothing, because no amount of penalty can bend a straight line.

Final test: once, on unseen data

After choosing every hyper-parameter on the validation set, we evaluated the four final models on the test set once. We wrote our own accuracy and confusion-matrix functions.

Press enter or click to view image in full size
Test results on 2,401 unseen rows. The RBF SVM misses only 6 of 1,096 faults; the linear models miss more than 600.

Notice the strange “0 false alarms” for the two linear models. They aren’t being careful. They are placing their line off to one side of the normal blob, so they almost never say “fault” and miss about 60% of real faults. For a relay, that is the worst possible behaviour.

Which model would we put in a relay?

For a protection system, the two errors are not equal. A false alarm trips the breaker unnecessarily: annoying and costly, but nothing gets destroyed. A missed fault leaves a short circuit running, which can damage equipment, start fires and destabilise the grid.

So we would deploy the RBF SVM: it misses only 6 of 1,096 faults and has the fewest false alarms. Logistic regression on Set Q is a strong, simpler runner-up that is easy to explain through its weights, but it misses 7.5 times more faults.

A healthy dose of scepticism

These numbers are almost certainly optimistic. The rows are consecutive time samples, and neighbouring rows are nearly identical (they differ by about 1% of a standard deviation). Because we split randomly, 84.5% of our test rows have their direct time-neighbour in the training set. The model is often tested on near-copies of points it has already seen, which especially helps the RBF SVM, since it classifies by closeness to training points.

A real relay would face new fault locations, different fault resistances, different loads, and real sensor noise instead of a clean simulation. A fairer test would split by fault event or by time block, so no part of a test fault was ever seen in training.

Takeaways

  1. A straight line can’t detect a fault from raw instantaneous values, because a fault makes the current large in either direction, and the normal points end up surrounded by fault points.
  2. Changing the features (adding squares) lets the very same linear model jump from 73% to 98%, and its weights match the physics: current up, voltage down.
  3. Changing the classifier (RBF kernel) gets to 99.6% with only 6 missed faults, without any hand-made features.
  4. Accuracy isn’t the whole story. For a relay, count the missed faults first.

The code, tables, and a small Streamlit app that runs both saved models side by side are on GitHub: https://github.com/MoomalEmaan/Detecting-Faults-on-a-Three-Phase-Transmission-Line.

--

--