Open to OpportunitiesTehan Wijeratne — CSE - First Direct Banking Operations UK
Open to Opportunities
Let's Talktehanwijeratne7@gmail.com
← Back home

Understanding Machine Learning

I wanted to understand how machine learning actually works. Not to become an expert, but to appreciate the abstractions behind the tools I’m learning at university.

This note is for other beginners. I’ll use one example throughout: predicting the age of an abalone (a type of sea snail) from simple measurements.

Software vs machine learning#

Normal software is deterministic. A developer writes explicit rules, and the same input gives the same output.

Machine learning is different. Instead of writing the rules, you give a model examples and let it find patterns. For abalone, the examples are measurements (length, diameter, shell weight) paired with a known number of shell rings. Age is about the ring count plus 1.5 years.

Train and test#

If you test a student on the exact questions they practised, you learn nothing about whether they understand the subject.

So we split the data:

  • Training set: what the model learns from
  • Test set: questions it has never seen
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

The test score is the only number worth reporting.

Overfitting#

A model that memorises the training data scores brilliantly on practice questions and badly on new ones. It’s like memorising answers instead of understanding the topic.

A good sign: training and test scores are close. A warning sign: a huge gap.

Data leakage#

This is the sneakiest mistake. If any information from the test set sneaks into training, your score is fake.

Common ways it happens:

  1. Scaling or cleaning the whole dataset before splitting
  2. Including a column that is secretly derived from the answer
  3. Duplicate rows landing on both sides of the split

The fix is boring: split first, then do everything else inside a pipeline.

Comparing models#

Don’t fall in love with one model. Try a simple baseline first (linear regression), then more complex ones (random forest, gradient boosting). If the fancy one only beats the baseline by a hair, take the simple one.

Takeaways#

  • It’s math plus data, not magic
  • A good evaluation matters more than a good model
  • A suspiciously great score deserves more scrutiny than a bad one

More writing

Certificate viewer

Send an email

Choose your email app or a webmail service.

tehanwijeratne7@gmail.com

If your email app does not open, choose Gmail or Outlook.