What Is Machine Learning?
Machine Learning is a way of teaching a computer to learn useful patterns from data and use those patterns to make predictions or decisions.
Let's Start With a Simple Example
Imagine you want a computer to identify whether an email is spam.
You could give the computer many emails that have already been classified:
After seeing many examples, a Machine Learning algorithm can learn patterns that are useful for distinguishing spam from normal emails.
Then Give It a New Email
The computer can use what it learned from previous examples to make a prediction about this new email.
Notice What Happened
The computer receives data from the past.
An algorithm learns useful relationships in that data.
The trained model can make predictions on new data.
Does the Computer "Understand" the Email?
Not in the way a human understands an email.
This is an important distinction. The model doesn't need human-like understanding to make a useful prediction.
It learns patterns from the data according to the algorithm and model being used.
The computer is not suddenly becoming intelligent. It is using data, an algorithm, and a model to produce useful predictions or decisions.
Machine Learning Is Used Everywhere
Traditional Programming vs Machine Learning
The biggest difference is not that one uses code and the other doesn't. Both use code.
The important difference is where the rules come from.
Traditional Programming
In traditional programming, a developer writes the rules that tell the computer what to do.
A Simple Example
Suppose you want to determine whether someone is eligible for a discount.
You could explicitly write the rule:
The computer doesn't need to discover this rule. You gave it the rule.
if age >= 60:
discount = True
else:
discount = False
This works very well when we already know the rules.
But Some Problems Don't Have Simple Rules
Now consider spam detection.
Could we write a few simple rules that correctly identify every spam email?
These rules might catch some spam.
But they will also make mistakes.
A legitimate email might contain the word "free". A spam email might never contain any of those words.
This Is Where Machine Learning Changes the Approach
Instead of manually writing every rule, we can provide examples and let an ML algorithm learn useful patterns from those examples.
The Direction Has Changed
Humans define the rules.
The algorithm learns useful rules or relationships from the examples.
Another Example: House Prices
Imagine trying to manually write every rule that determines a house's price.
Now combine those with hundreds of other factors: neighborhood, parking, floor, construction quality, nearby schools, market conditions, and so on.
The number of possible combinations becomes enormous.
This is exactly the kind of situation where manually writing every rule becomes impractical.
Does Machine Learning Mean We Don't Write Rules?
No.
This is a common beginner misunderstanding.
Developers still write the software, choose the algorithm, prepare the data, define the training process, and decide how the model will be used.
What changes is that we don't have to manually specify every relationship that the model needs to use.
Traditional programming is excellent when the rules are clear and manageable.
But some real-world problems contain patterns that are too complicated to describe manually.
That's the problem Machine Learning is designed to help with.Why Do We Need Machine Learning?
Traditional programming is excellent when we can clearly describe the rules of a problem.
The problem starts when the rules become too complicated, too numerous, or difficult to write manually.
Problem 1: Some Rules Are Easy to Write
Consider a simple banking rule.
That's easy to write as a normal program because we know exactly what the rule is.
Problem 2: Some Problems Have Too Many Rules
Now consider spam email detection.
A spam email could contain words such as:
But legitimate emails can contain these words too.
So we would need many more rules:
And the combinations between these signals can become extremely complicated.
Problem 3: Some Patterns Are Difficult to Describe
Consider recognizing a cat in a photograph.
How would you write a complete set of rules for a computer?
These rules are not enough.
A cat can appear from different angles, under different lighting conditions, with different colors, and in different positions.
Writing rules for every possible image would be extremely difficult.
This Is Where Machine Learning Helps
Instead of trying to manually write every possible rule, we can provide the computer with many examples.
Give the system many examples.
An ML algorithm learns useful relationships.
Use what was learned on new data.
Another Important Reason: The World Changes
Real-world patterns don't stay exactly the same forever.
For example, the characteristics of spam emails can change. New words, new scams, and new techniques appear over time.
A system that depends entirely on manually written rules may require constant updates.
A Machine Learning system can be retrained using newer data so that the model can adapt to changing patterns.
Where Machine Learning Becomes Useful
Spam Detection
Learn patterns in emails.
Image Recognition
Learn patterns in images.
Fraud Detection
Learn unusual transaction patterns.
Recommendations
Learn from user behavior.
But ML Is Not Always the Best Choice
This is important.
You should not use Machine Learning simply because it is available.
If a simple rule solves the problem reliably, a normal program is often easier to build, test, understand, and maintain.
Usually the simpler solution.
Useful when rules are difficult to define manually and sufficient data is available.
It is another approach for solving problems where learning patterns from data can be more practical than manually writing every rule.
Instead of talking about ML abstractly, we're going to take one concrete problem and work through it from beginning to end.
Our first problem: predicting house prices.Finding the Pattern With Simple Math
We have four houses with known sizes and prices. Before using Machine Learning, let's see if we can find the relationship ourselves.
Look at the Data
| House Size | Price |
|---|---|
| 800 sq ft | ₹30 lakh |
| 1000 sq ft | ₹40 lakh |
| 1200 sq ft | ₹50 lakh |
| 1500 sq ft | ₹65 lakh |
Notice something interesting.
When the house size increases, the price also increases.
But let's go one step further. Can we measure exactly how the price changes?
Step 1: Compare Two Houses
Take the first two houses:
The size increased by:
The price increased by:
Step 2: How Much Price Changes for Each Square Foot?
We know that an additional 200 sq ft corresponds to an additional ₹10 lakh in this simplified dataset.
So the price increase per square foot is:
Since ₹0.05 lakh is ₹5,000:
Step 3: Can We Write This as an Equation?
Yes.
We can describe the relationship using:
In Machine Learning and mathematics, we often write this more generally as:
Here:
Let's Check Our Equation
We shouldn't just assume the equation is correct. Let's test it against the houses we already know.
For an 800 sq ft house
Price = 0.05 × 800 − 10
= 40 − 10
= ₹30 lakh
For a 1200 sq ft house
Price = 0.05 × 1200 − 10
= 60 − 10
= ₹50 lakh
Both predictions match our original data.
So What Did We Actually Find?
We found a mathematical relationship between house size and house price.
Now We Can Predict a New House
Remember our new house from the previous section?
We can put 1400 into our equation.
Price = 0.05 × 1400 − 10
= 70 − 10
= ₹60 lakh
According to the simple relationship we found, a 1400 sq ft house would be predicted at approximately ₹60 lakh.
We Just Did Something Important
We started with examples.
Then we found a relationship in those examples.
Finally, we used that relationship to predict something we didn't know.
We used mathematics manually here. Later, we will give the data to a Machine Learning algorithm and let it learn the relationship for us.
One Important Warning
Our example is deliberately simple.
Real house prices do not depend only on size. Location, number of bedrooms, age, condition, parking, neighborhood, and many other factors can affect the price.
That's why real Machine Learning problems are more complicated than this example.
We found a relationship that fits the data perfectly. What happens when real-world data doesn't fit a simple relationship so neatly?
Next: Why Predictions Aren't PerfectWhy Predictions Aren't Perfect
In our previous example, the numbers were unusually clean. Every house followed almost exactly the same relationship.
Real-world data is rarely that simple.
Let's Make the Data More Realistic
Imagine that we collect information about houses from a real city.
| House Size | Actual Price |
|---|---|
| 800 sq ft | ₹32 lakh |
| 1000 sq ft | ₹41 lakh |
| 1200 sq ft | ₹47 lakh |
| 1400 sq ft | ₹58 lakh |
| 1500 sq ft | ₹68 lakh |
The pattern is still there: larger houses generally cost more.
But the numbers don't follow one perfectly straight rule.
Why Are the Prices Different?
House size is only one factor that affects price.
Two houses with the same size can have very different prices.
Good location
New construction
Parking available
Less convenient location
Older construction
No parking
Both houses have the same size. But their prices are different.
This tells us something important:
Other information also matters.
What Other Information Could Matter?
So What Happens to Our Prediction?
Suppose we use our simple equation from the previous section:
For a 1400 sq ft house:
Price = 0.05 × 1400 − 10
= ₹60 lakh
But imagine the actual selling price was ₹58 lakh.
Our prediction was not exactly correct.
But that does not automatically mean the prediction was useless.
Prediction vs Reality
Machine Learning usually works with patterns rather than perfect rules.
The goal is often to find a relationship that makes useful predictions, even though the prediction may not exactly match reality every time.
Does More Data Solve Everything?
Not necessarily.
More examples can help a model learn a better pattern, but the quality of the data also matters.
If the data is incomplete, incorrect, biased, or missing important information, the model can still make poor predictions.
We also need useful information and reliable examples.
This Gives Us an Important Insight
In our first example, we only used house size.
But real house prices depend on many things.
So a real Machine Learning system could use several pieces of information together.
→ Predict House Price
It was intentionally simplified so we could understand the basic idea first.
Real Machine Learning becomes more interesting when we have messy data, multiple factors, and imperfect predictions.
If we give a Machine Learning system all these examples, what exactly does the machine learn from them?
Next: What Does the Machine Actually Learn?What Does the Machine Actually Learn?
We keep saying that a Machine Learning system "learns patterns from data."
But what does that actually mean?
Let's go back to our house-price example and look at it more closely.
Remember Our Data
| House Size | Actual Price |
|---|---|
| 800 sq ft | ₹30 lakh |
| 1000 sq ft | ₹40 lakh |
| 1200 sq ft | ₹50 lakh |
| 1500 sq ft | ₹65 lakh |
We noticed that larger houses generally have higher prices.
Instead of remembering every house individually, we want to describe the relationship between size and price.
We Can Describe the Relationship With an Equation
In our simplified example, we found:
There are two important numbers in this equation:
These Numbers Describe What Was Learned
This is the important idea.
The machine does not need to memorize:
- "800 sq ft house costs ₹30 lakh"
- "1000 sq ft house costs ₹40 lakh"
- "1200 sq ft house costs ₹50 lakh"
- "1500 sq ft house costs ₹65 lakh"
Instead, it can learn a relationship that helps explain how house size is related to price.
In this simple example, those values are the numbers used in our equation.
Let's See What Those Numbers Do
Suppose the learned relationship is:
Now give the relationship a new input:
The learned relationship is used to calculate the prediction:
Price = 0.05 × 1400 − 10
Price = 70 − 10
Price = ₹60 lakh
Notice what happened.
We gave the system a house size it had not seen before, and the learned relationship produced an estimated price.
So What Is the Machine Learning Part?
Up to now, we calculated the relationship ourselves.
We manually decided that:
That's not really Machine Learning yet.
The interesting part is when we give the examples to a Machine Learning algorithm and ask it to find useful values for the relationship.
House sizes and their known prices.
Find values that describe the data.
Apply the learned relationship to new houses.
What If We Had More Information?
Real house prices depend on much more than size.
Suppose we give the system:
Now the relationship becomes more complicated.
Instead of one input, the system has several inputs that can influence the prediction.
The Machine Doesn't Learn "House Prices"
This is another important distinction.
The machine does not learn a universal rule such as:
That would be wrong.
Instead, it learns a relationship from the particular data it was given.
If the data changes, the learned relationship can also change.
A Simple Way to Think About It
We have data, but don't yet know the useful relationship.
Values that describe the relationship found in the training data.
Use the learned relationship to estimate an output.
And what do we actually mean when we call something a "Machine Learning model"?
Next: What Is a Model?What Is a Model?
We just saw that Machine Learning can learn a relationship from examples. That learned relationship is what we call a model.
The word "model" can sound complicated, but the basic idea is actually simple.
Let's Go Back to Our House Example
We had examples of house sizes and their prices:
| House Size | Price |
|---|---|
| 800 sq ft | ₹30 lakh |
| 1000 sq ft | ₹40 lakh |
| 1200 sq ft | ₹50 lakh |
| 1500 sq ft | ₹65 lakh |
From this data, we found a simplified relationship:
That Relationship Is Our Model
The equation gives us a way to turn a house size into a predicted price.
That's why we can treat it as our simple Machine Learning model.
Input a house size → get a predicted price.
Let's Use the Model
Suppose a new house is:
We give that input to our model:
Price = 0.05 × 1400 − 10
Price = 70 − 10
Predicted Price = ₹60 lakh
The model didn't need us to manually create a new rule for the 1400 sq ft house.
It used the relationship it already had to calculate the prediction.
A Model Is Not the Same as the Data
This distinction is important.
The houses we used for learning are the data.
The learned relationship is the model.
800 sq ft → ₹30L
1000 sq ft → ₹40L
1200 sq ft → ₹50L
Find values that describe the pattern.
Price = 0.05 × Size − 10
Why Do We Need a Model?
Because we want to use what was learned later.
Imagine that our system learned from 100,000 houses. We don't want to go through all 100,000 houses every time someone asks for a prediction.
We want to use the learned result to make predictions quickly.
Is a Model Always Just an Equation?
No.
Our equation is only a very simple example. Different Machine Learning problems use different types of models.
A model could represent a mathematical equation, a set of decision rules, a tree of decisions, or a much more complex mathematical structure.
Model vs Prediction
These two terms are often confused by beginners.
The model is what was learned.
The prediction is the answer produced when we give new data to that model.
The learned relationship.
Input the model has not seen before.
The model's estimated output.
The model is the learned relationship that produces predictions when new data is provided.
One More Important Point
A model is not automatically correct just because it has learned something.
A model can learn a poor relationship if the training data is poor, insufficient, or misleading.
That's why Machine Learning doesn't stop after creating a model. We also need to evaluate how well the model performs.
We have data, we have learning, and we have a model. But there are two different moments in this process: learning from data and using what was learned.
Next: Training vs PredictionTraining vs Prediction
We now know what data, learning, and a model are. The next important distinction is understanding what happens during training and what happens after training when we make a prediction.
First: What Is Training?
Training is the process where a Machine Learning algorithm looks at examples and learns a useful relationship from them.
Let's use our house-price example again.
Our Training Data
| House Size | Known Price |
|---|---|
| 800 sq ft | ₹30 lakh |
| 1000 sq ft | ₹40 lakh |
| 1200 sq ft | ₹50 lakh |
| 1500 sq ft | ₹65 lakh |
During training, the algorithm uses these examples to find a relationship between house size and house price.
What Happens During Training?
Conceptually, the process looks like this:
House sizes and their known prices.
The algorithm searches for a relationship that fits the examples.
Values that describe the learned relationship.
In our simplified example, suppose training produces:
That learned relationship is now our model.
Training Is Learning From Known Examples
Notice that during training, we already know the correct prices.
For example, the algorithm knows that the 1000 sq ft house actually sold for ₹40 lakh.
It uses these known examples to learn the relationship.
Now Training Is Finished
Once the model has been trained, we can use it.
Now suppose a completely new house arrives:
We don't know its actual selling price yet.
We give the 1400 sq ft input to the trained model.
What Is Prediction?
Prediction is using a trained model with new data to produce an estimated output.
The model is no longer learning the basic relationship from scratch. It is applying what it already learned.
Training and Prediction Are Different
Here's the simplest way to separate them.
| Training | Prediction |
|---|---|
| Uses known examples | Uses new data |
| Learns the relationship | Uses the learned relationship |
| Produces a trained model | Produces an estimated output |
A Simple Real-Life Analogy
Think about learning to recognize different types of fruit.
Someone shows you many examples and tells you:
- "This is an apple."
- "This is a banana."
- "This is an orange."
You observe their characteristics and learn how to distinguish them.
Later, someone gives you a fruit you've never seen before and asks:
You use what you learned to make your answer.
The learning process is similar to training. Identifying the new fruit is similar to making a prediction.
Does Prediction Always Mean a Number?
No.
The output depends on the Machine Learning problem.
House price: ₹60 lakh
Spam detection: Spam
Image classification: Cat
Customer prediction: Likely to buy
One Common Beginner Mistake
Beginners sometimes think that the model continuously learns every time it makes a prediction.
That's not necessarily true.
In a simple prediction system, the model can already be trained and then simply be used to produce predictions.
Training creates or updates what the model has learned. Prediction uses that learned model on new data.
Put Everything Together
Size + known price
Find a useful relationship
Can be reused
Unknown price
Estimated output
Now it's time to stop doing the calculations manually. Let's build this simple example using Python and see what an actual Machine Learning library does.
Next: Build It With PythonBuild It With Python
So far, we calculated the relationship between house size and price ourselves.
Now let's let Python and a Machine Learning library do the learning for us.
What Are We Going to Build?
We want a program that can look at examples like these:
| House Size | Price |
|---|---|
| 800 sq ft | ₹30 lakh |
| 1000 sq ft | ₹40 lakh |
| 1200 sq ft | ₹50 lakh |
| 1500 sq ft | ₹65 lakh |
Then we want it to learn the relationship and predict the price of a new house.
Step 1: Import the Machine Learning Tool
We'll use scikit-learn, one of the most commonly used Python libraries for Machine Learning.
from sklearn.linear_model import LinearRegression
This imports the LinearRegression algorithm.
Linear regression is a good choice for our first example because we are trying to predict a numerical value: house price.
Step 2: Create the Training Data
Next, we give Python the house sizes and their known prices.
X = [[800],
[1000],
[1200],
[1500]]
y = [30, 40, 50, 65]
Here we use the price in lakhs to keep the numbers simple.
Step 3: Create the Model
Now we create a Linear Regression model.
model = LinearRegression()
At this point, the model has not learned our house-price relationship yet.
We have simply created the object that will perform the learning.
Step 4: Train the Model
Now comes the important part.
model.fit(X, y)
The fit() method tells the algorithm:
This is the training step we discussed earlier.
Step 5: Give It a New House
Now suppose we want to estimate the price of a:
We pass the new house size to the trained model.
prediction = model.predict([[1400]])
The model uses what it learned during training and returns a predicted price.
The Complete Program
Now let's put all the pieces together.
from sklearn.linear_model import LinearRegression
X = [[800],
[1000],
[1200],
[1500]]
y = [30, 40, 50, 65]
model = LinearRegression()
model.fit(X, y)
prediction = model.predict([[1400]])
print(prediction)
What Should We Expect?
The model looks at the training examples and finds the relationship that best fits them.
For our new 1400 sq ft house, it produces a prediction close to the relationship we calculated manually earlier.
The exact result comes from the relationship learned by the Linear Regression algorithm.
Compare What We Did Before and Now
We calculated the relationship manually and wrote the equation.
We give it examples and let Linear Regression find the relationship.
One Important Difference
Earlier, we already knew the equation:
In the Python version, we don't give that equation to the algorithm.
We only give it the examples:
X = [[800],
[1000],
[1200],
[1500]]
y = [30, 40, 50, 65]
The algorithm calculates the relationship itself.
Instead of manually writing the rule that connects the input to the output, we provide examples and let the algorithm learn the rule.
What Just Happened?
House sizes + known prices
Finds the relationship
Stores the learned relationship
1400 sq ft
Estimated price
If you understand what each line is doing, you understand the basic workflow of a Machine Learning program.
Next: Understand the Python CodeTry It Yourself
You have seen how the model is created, trained, and used for prediction. Now change the input yourself and see what the model does.
This is where the idea becomes easier to understand. Don't just read the code — experiment with it.
Start With the Same Model
Run this code first without changing anything.
from sklearn.linear_model import LinearRegression
X = [[800],
[1000],
[1200],
[1500]]
y = [30, 40, 50, 65]
model = LinearRegression()
model.fit(X, y)
prediction = model.predict([[1400]])
print(prediction)
The model produces an estimated price based on the relationship it learned from the training data.
Experiment 1: Change the House Size
Find this line:
prediction = model.predict([[1400]])
Change 1400 to 1800.
prediction = model.predict([[1800]])
Run the program again.
The model will produce a different prediction because you gave it a different input.
One prediction
Different input
The model calculates again
Why Did the Prediction Change?
Because the model learned a relationship between house size and price.
When the size changes, the input to that relationship changes, so the predicted price changes too.
Experiment 2: Try Another House
Now try:
prediction = model.predict([[1100]])
Run the program.
Then try:
prediction = model.predict([[2000]])
Run it again.
| New House | What Should Happen? |
|---|---|
| 1100 sq ft | Model produces a prediction |
| 1400 sq ft | Model produces a prediction |
| 1800 sq ft | Model produces a prediction |
| 2000 sq ft | Model produces a prediction |
Experiment 3: Ask for Several Houses at Once
You don't have to make one prediction at a time.
Try:
prediction = model.predict([
[900],
[1300],
[1700],
[2000]
])
print(prediction)
Now the model receives four new house sizes.
It returns four predicted prices — one for each house.
Important: We Did Not Retrain the Model
Look carefully at what we changed.
We changed:
model.predict([[1400]])
We did not change:
model.fit(X, y)
The model was already trained.
We are simply giving the trained model different inputs.
Once the model is trained, you can use it with many different inputs without retraining it every time.
Experiment 4: Change the Training Data
Now let's do something more interesting.
Change one of the known prices:
y = [30, 45, 50, 65]
We changed the price of the 1000 sq ft house from 40 to 45.
Now train the model again:
model.fit(X, y)
Then predict the price of a 1400 sq ft house:
prediction = model.predict([[1400]])
You should get a different prediction than before.
Why Did the Model Change?
Because the training data changed.
The model learns from the data you give it. If the examples change, the relationship learned from those examples can change as well.
Your Turn: Make Three Changes
Try these experiments yourself.
Change only the value inside predict().
Keep the training data unchanged.
Train the model again and compare the prediction.
Ask Yourself These Questions
- What happens when I increase the house size?
- What happens when I decrease the house size?
- What happens when I change the training data?
-
Do I need to call
fit()every time I callpredict()?
What You Just Experienced
You didn't manually calculate a new equation for every house.
You trained the model once and then gave it different inputs.
That's one of the useful ideas behind Machine Learning: the learned relationship can be reused on new data.
But something important happened when we changed the training data. The model's behavior changed too. Let's understand exactly why.
Next: What Happens When the Data Changes?Key Takeaways
If you remember only a few things from this lesson, remember these.
Instead of manually writing every rule, we provide data and allow an algorithm to learn useful relationships from it.
In our house-price example, the house sizes were the inputs and the known prices were the target values.
The model can then use what it learned when it receives new input.
fit() trains the model.
predict() uses the trained model to
produce an output.
A model can make useful predictions, but a prediction is not automatically guaranteed to be correct.
If the training data changes and the model is trained again, what the model learns can change.
Useful, accurate, and relevant data matters more than simply having a larger amount of data.
The One Flow to Remember
That is the basic Machine Learning workflow you learned in this lesson.
model = LinearRegression()
model.fit(X, y)
model.predict([[1400]])
If you can explain what each line does in your own words, you understand the core of this lesson.
Now let's look at where this foundation leads and what you'll learn next.
Next: What You'll Learn Next