What Is Machine Learning?
Machine learning is a way of building software that learns its rules from examples, instead of a programmer writing every rule by hand.
Your Path Through This Lesson
0 of 5 done
- Explain how machine learning differs from writing rules by hand.
- Name the feature, target, model and prediction in a real example.
- Train and use your first model in five lines of Python.
Start With a Problem You Already Know
Say you're a teacher. Five of your students told you how many hours they studied for a test, and you have their marks:
| Student | Hours studied | Marks |
|---|---|---|
| Noman | 1 | 20 |
| Lamia | 2 | 40 |
| Rafi | 3 | 50 |
| Tanvir | 4 | 40 |
| Arif | 5 | 50 |
A new student says, "I'm going to study for 6 hours." Roughly what will they score?
You probably already have a feeling: more hours, more marks, but not perfectly. Your brain looked at the examples, found a pattern, and used it to guess. That is exactly what machine learning does, except the computer does it with maths, and it can do it with millions of rows instead of five.
Watch the whole idea in under 20 seconds:
Traditional Programming vs Machine Learning
In traditional programming you write the rules. You give the computer the data and the rules, and it gives you answers.
In machine learning you flip it around. You give the computer the data and the answers (the marks), and it figures out the rules for you.
Why does that matter? Because for many problems, nobody can write the rules:
- What exact rule tells a spam email apart from a normal one?
- What rule says which photo has a cat in it?
- What rule predicts how long a food delivery will take in Dhaka traffic at 7 pm?
You can't write those rules down, but you can collect examples. Give enough examples to a machine learning algorithm and it finds the rules itself.
The Words You'll Hear Every Day
Let's give names to the pieces of our marks problem. You'll see these words in every single lesson after this one.
| Word | Meaning | In our example |
|---|---|---|
| Dataset | All the examples you have | The table of 5 students |
| Feature (input, ) | What you know | Hours studied |
| Target (label, output, ) | What you want to predict | Marks |
| Model | The pattern the algorithm learns | A rule like marks ≈ 22 + 6 × hours |
| Training | The process of learning the pattern from data | Fitting the rule to the 5 students |
| Prediction () | The model's answer for a new input | 58 marks for 6 hours |
The little hat in (say it "y-hat") always means predicted. Plain is the real answer, is the model's guess. Keeping these two apart will save you a lot of confusion later.
Your First Model in Five Lines
You don't need to understand every line yet. Just see how short it is: give the model examples, let it learn, ask it a question.
from sklearn.linear_model import LinearRegression
hours = [[1], [2], [3], [4], [5]] # feature: one column, so each row is a list
marks = [20, 40, 50, 40, 50] # target
model = LinearRegression()
model.fit(hours, marks) # training: learn the pattern
print(model.predict([[6]])) # prediction for a new student[58.]The model learned the rule marks ≈ 22 + 6 × hours, and for 6 hours it says 58 marks. In the simple linear regression lesson you'll calculate those same numbers, 22 and 6, by hand.
Notice hours is written as [[1], [2], ...], a list of lists, not [1, 2, ...]. scikit-learn always expects the features as a 2D table: rows are examples, columns are features. Passing a flat list is the number one beginner error, and we'll look at it closely later.
Where Machine Learning Shows Up
You use machine learning many times a day without noticing:
- Recommendations. YouTube, Netflix and online shops guess what you'll want next from what people like you watched or bought.
- Spam filters. Your email learns spam from millions of emails people have already marked.
- Maps and delivery apps. Arrival times are predicted from past trips at the same time of day.
- Banks. Fraud detection flags a card payment that doesn't look like your usual ones.
- Phones. Face unlock, voice typing, and photo search ("show me photos of the beach").
The Machine Learning Workflow
Every project in this course, however fancy, follows the same loop:
- Collect data. Examples with inputs, and answers if you have them.
- Prepare it. Clean mistakes, fill missing values, turn text into numbers.
- Split it. Keep some data aside for testing (see train and test split).
- Train a model on the training data.
- Evaluate it on the test data it has never seen.
- Improve and repeat, then use it to make predictions.
Change the last line to predict for 0 hours and for 10 hours. Do both answers make sense? (The 0-hour answer is 22. Would a student who didn't study at all really get 22? Keep that question in mind: it comes back when we talk about the intercept.)
A model is a rule learned from examples. You supply the inputs and the answers; the algorithm supplies the rule.
Summary
- Machine learning learns rules from examples instead of a programmer writing them.
- A feature is what you know, the target is what you want to predict, and the model is the learned pattern.
- is the real answer and is the prediction.
- Next, let's clear up a confusing set of words: AI, ML, DL and data science.