0% found this document useful (0 votes)
17 views25 pages

ML Chapter0

Chapter 0 of 'Machine Learning — A Complete Guide' introduces the concepts of intelligence, artificial intelligence (AI), machine learning (ML), and deep learning (DL) in an accessible manner for beginners. It explains the distinctions between these terms, the foundational principles of how computers learn from data, and provides real-world applications of ML. The chapter emphasizes that while computers can simulate thinking by finding patterns in data, they do not possess true intelligence or consciousness.

Uploaded by

Rudra Abhishek
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views25 pages

ML Chapter0

Chapter 0 of 'Machine Learning — A Complete Guide' introduces the concepts of intelligence, artificial intelligence (AI), machine learning (ML), and deep learning (DL) in an accessible manner for beginners. It explains the distinctions between these terms, the foundational principles of how computers learn from data, and provides real-world applications of ML. The chapter emphasizes that while computers can simulate thinking by finding patterns in data, they do not possess true intelligence or consciousness.

Uploaded by

Rudra Abhishek
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Machine Learning — A Complete Guide | Chapter 0

MACHINE LEARNING
A Complete Guide — From Zero to Understanding

CHAPTER 0
How Do Computers Actually "Think"?
Covering: Intelligence · AI vs ML vs DL · Real-World Applications · First Python Code

WHO IS THIS CHAPTER FOR?


This chapter is written for anyone — Class 8 students, college freshers, working
professionals — who wants to understand AI and Machine Learning from the ground
up. No prior knowledge required. We will build intuition first, then introduce the math
and code gently, like peeling an onion — one layer at a time.

By the end of this chapter you will be able to:


• Explain clearly what intelligence is — and why machines can simulate it
• Distinguish between AI, Machine Learning, and Deep Learning — with zero confusion
• Describe how a computer learns from data, step by step
• Recognise ML in apps you use every day
• Run and understand your first real Python ML code snippet

Page 1
Machine Learning — A Complete Guide | Chapter 0

0.1 What Is Intelligence?


Let us start at the very beginning — not with code, not with math, but with a question that
philosophers have debated for centuries. What does it mean to be intelligent?

📖 A Story First

Priya is a 10-year-old girl. One afternoon, her younger brother Arjun spills his glass
of milk on the floor. Priya has never been told what to do in this exact situation —
nobody gave her a step-by-step instruction manual. But she immediately does four
things:

1. She recognises the problem (wet floor → danger of slipping).


2. She recalls similar past events (she has seen spills before).
3. She plans a solution (get a cloth, wipe it up).
4. She adapts — realising she needs a mop instead of a cloth because the spill is large.

This — the ability to learn from experience, adapt to new situations, and solve
problems without being explicitly told how — is the core of intelligence.

So What Exactly IS Intelligence? A Working Definition


Psychologists and scientists have argued about this for decades. But for our purposes, we will
use this practical definition:

Intelligence =
The ability to acquire knowledge from experience,
reason about it, and apply it flexibly to new situations.

The 5 Pillars of Intelligence


When scientists study intelligence, they break it into these five core abilities:

Pillar What It Means Human Example Machine Equivalent?


Learning Improving from Baby learning to walk Training on data
past experience

Page 2
Machine Learning — A Complete Guide | Chapter 0

Reasoning Applying logic to Solving a maths Decision trees, logic rules


reach conclusions puzzle
Perception Sensing and Seeing, hearing, Computer vision, speech
interpreting the touching recognition
world
Language Understanding and Reading this sentence Natural language
producing processing (NLP)
communication
Adaptation Handling brand- Using an umbrella in Generalisation in ML
new situations a sandstorm models

💡 Key Insight

Notice that intelligence is NOT about being fast. A calculator is extremely fast — it can
do a million additions per second. But it has zero intelligence. Why? Because it cannot
learn from experience or adapt. It can only do exactly what it was told, every single
time.

Page 3
Machine Learning — A Complete Guide | Chapter 0

Human Intelligence vs. Machine Intelligence — Side by Side

HUMAN BRAIN COMPUTER / AI


Neurons: ~86 billion Transistors: Trillions in modern GPUs
Speed: ~200 operations/second per neuron Speed: Billions of operations per second
(slow!) (fast!)
Learning: Continuous — from every Learning: Only from structured training data
experience
Memory: Perfect — never forgets what it
Memory: Lossy — we forget, misremember, stored
distort
Generalisation: Still a major challenge —
Generalisation: Excellent — sees a new can fail on slight variations
dog, still knows it is a dog
Power usage: Hundreds to thousands of
Power usage: ~20 Watts (an LED bulb!) Watts
Weakness: Easily distracted, emotionally Weakness: No common sense, no true
biased, slow at arithmetic creativity, no physical intuition

Here is something surprising: Computers are both smarter AND dumber than humans —
depending on the task. A laptop can multiply two 20-digit numbers in a nanosecond. But it
would completely fail to understand that 'it is raining cats and dogs' does not mean actual
animals are falling from the sky. Humans understand context, metaphor, and nuance
effortlessly. Machines still struggle with these enormously.

Page 4
Machine Learning — A Complete Guide | Chapter 0

0.2 The Big Three: AI, ML, and Deep Learning


These three terms are thrown around constantly — often interchangeably, which causes
enormous confusion. Let us settle this once and for all with a clear analogy.

🧅 The Onion Analogy

Think of it like an onion with three layers, where each inner layer is a more specific
version of the outer one:

╔═════════════════════════════════════════════════════════════════
═╗


║ ARTIFICIAL INTELLIGENCE (AI) ─── The big idea

║ Any technique that lets machines mimic human intelligence



║ ┌──────────────────────────────────────────────────────┐

║ │ │

║ │ MACHINE LEARNING (ML) ─── A smarter method │

║ │ Systems that learn from data automatically │

║ │ │

║ │ ┌──────────────────────────────────────────┐ │

║ │ │ │ │

║ │ │ DEEP LEARNING (DL) ─── The powerhouse │ │

║ │ │ ML using many-layered neural networks │ │

║ │ │ │ │

║ │ └──────────────────────────────────────────┘ │

║ └──────────────────────────────────────────────────────┘

Page 5
Machine Learning — A Complete Guide | Chapter 0

╚═════════════════════════════════════════════════════════════════
═╝

Everything inside is a subset of everything outside. All Deep Learning is Machine Learning. All
Machine Learning is AI. But not all AI is Machine Learning, and not all ML is Deep Learning.

Artificial Intelligence (AI)


AI is the broadest term. It simply means: building machines that can perform tasks that would
normally require human intelligence.

The idea is not new. The term 'Artificial Intelligence' was coined in 1956 by John McCarthy at a
conference at Dartmouth College. Early AI approaches were rule-based — programmers
manually wrote every single rule the computer should follow.

🎮 Classic AI Example: A Chess Program (1990s style)

Old chess programs like Deep Blue worked by brute force rules:

• 'If your rook is on the same column as the opponent's king, check if the path is clear.'
• 'If the opponent's queen is threatening your knight, move the knight.'
• ...and thousands more such rules, all hand-coded by programmers.

This IS artificial intelligence. But it is NOT machine learning — because the program
learned nothing from experience. Every rule was written by a human, manually.

Machine Learning (ML)


Machine Learning flips the old model completely on its head. Instead of programmers writing
rules, we give the machine data and let it figure out the rules by itself.

Traditional Programming (Old Machine Learning


AI)
What you provide Input Data + Rules you wrote Input Data + Correct Answers
(labels)

Page 6
Machine Learning — A Complete Guide | Chapter 0

What you get Output (answers) A Model that can produce


back answers
Who writes the Programmer (you!) The algorithm — automatically!
rules?
Example IF temperature > 35 THEN 'hot' Model learns 'hot' boundary from
10,000 weather records
Scales with data? No — more data → more rules Yes! More data → model gets
needed smarter

💡 The Core Insight of ML

The fundamental shift of Machine Learning is this: instead of telling the computer
WHAT to do, we show it EXAMPLES of what good answers look like, and the computer
figures out the pattern on its own. This is exactly how human children learn — not by
reading rule books, but by experiencing the world.

Deep Learning (DL)


Deep Learning is a specific type of Machine Learning that uses structures loosely inspired by
the human brain, called Artificial Neural Networks. The 'deep' part refers to having many
layers in these networks — sometimes hundreds of layers deep.

Deep Learning requires:


• Huge amounts of data (millions or billions of examples)
• Massive computational power (specialised GPUs or TPUs)
• Sophisticated training algorithms (backpropagation — we will cover this later!)

In return, Deep Learning can solve problems that ordinary ML cannot — like recognising faces
in photos with 99% accuracy, translating languages in real-time, generating human-like text
(like ChatGPT), or detecting cancer in X-rays better than doctors.

Feature Traditional ML Deep Learning


Data needed Hundreds to thousands of Millions+ examples
examples
Feature engineering Human must decide which Learns features automatically
features matter
Interpretability Usually explainable (you can 'Black box' — hard to explain
read the rules) why

Page 7
Machine Learning — A Complete Guide | Chapter 0

Performance on Limited State of the art (best in the


images/text world)
Training time Minutes to hours Hours to weeks (on expensive
hardware)
Best for Structured tabular data Images, audio, text, video
(spreadsheets)

Page 8
Machine Learning — A Complete Guide | Chapter 0

A Full Timeline — AI's History in One Visual

YEAR EVENT
SIGNIFICANCE
──────
─────────────────────────────────────────────────────────────
──────────────
1950 Alan Turing proposes the 'Turing Test'
AI is born as an idea
1956 'AI' coined at Dartmouth Conference
Official birth of the field
1960s First neural networks (Perceptron) created
Early DL ancestor
1980s Expert Systems rule AI — hand-coded rules everywhere
AI 'winter' approaches
1986 Backpropagation algorithm invented
Neural nets can now learn!
1997 Deep Blue beats world chess champion Kasparov
Milestone for game AI
2006 Geoffrey Hinton revives deep neural networks
Deep Learning is born
2012 AlexNet wins ImageNet — deep learning beats everything
ImageNet Revolution
2016 AlphaGo beats world Go champion
Deep RL milestone
2017 'Attention is All You Need' paper — Transformer invented
Foundation of ChatGPT
2020 GPT-3 released — AI can write like humans
NLP revolution
2022 ChatGPT launches — 100M users in 60 days
AI goes mainstream
2024 Multimodal AI (text+image+audio) — AI sees, hears,
speaks Where we are today

Page 9
Machine Learning — A Complete Guide | Chapter 0

0.3 How Do Computers Actually "Think"?


This is the question that trips most people up — and it has a beautifully simple answer once
you see it the right way.

Computers do NOT think. Not really. They do not have consciousness, opinions, feelings, or
desires. What they do have is an extraordinary ability to find patterns in numbers — and that
turns out to be enough to simulate thinking, to a remarkable degree.

🧠 The Core Secret

Everything in the world — every image, every sound, every word, every
temperature reading — can be converted into numbers. And once you have
numbers, you can find patterns. And once you find patterns, you can make
predictions. This is the entire foundation of Machine Learning.

Step 1 — The World Becomes Numbers


Let us see exactly how different types of information become numbers:

Real World Thing How It Becomes Numbers Example


A colour image Grid of pixels, each pixel = 3 numbers A 100×100 image =
(R, G, B), each from 0-255 30,000 numbers
A word / text Each word gets a unique ID number, 'cat' → [0.2, -0.5, 0.8, ...]
or a vector of hundreds of numbers
Sound / speech Sound wave sampled thousands of 1 second of audio ≈
times per second → list of amplitudes 44,100 numbers
Temperature Directly a number 37.2°C → 37.2
'Yes' or 'No' Binary encoding Yes → 1, No → 0
A video Sequence of image frames (each a 1 minute @ 30fps = 1,800
grid of numbers) images

🎯 Aha Moment

This is why Machine Learning can work on seemingly unrelated things — spam emails,
cancer detection, music recommendations — using the same core algorithms. They all

Page 10
Machine Learning — A Complete Guide | Chapter 0

boil down to: find patterns in arrays of numbers.

Step 2 — Finding a Pattern (Learning)


Here is where the actual 'learning' happens. We will build up to this concept carefully, starting
with the simplest possible example.

The Simplest Learning Problem: Predicting House Prices


Imagine you are a property agent. You have sold 6 houses. You recorded the size (in square
metres) and the selling price:

House Size (sq. metres) Price (₹ Lakhs)


House A 50 25
House B 80 41
House C 100 52
House D 120 63
House E 150 78
House F 200 104

A new house of 175 sq. metres comes on the market. What should it sell for?

You could eyeball the table and guess somewhere around ₹90 lakhs. That is actually your
brain doing informal ML — finding a pattern (bigger house → higher price) and extrapolating.

A machine would do this more formally. Let us plot these points and draw a line through them:

Price
(₹L) │ *
104
│ .
80 ──┤ * 78
│ .
60 ──┤ * 63
│ * 52
40 ──┤ * 41

Page 11
Machine Learning — A Complete Guide | Chapter 0

20 ──┤ * 25

0 ──┴────┬────┬────┬────┬────┬────┬────┬────┬────▶ Size
(sq.m)
50 75 100 125 150 175 200 225 250

* = actual data point . = best-fit line (the 'model')


? At 175 sq.m → line predicts approximately ₹91 lakhs

The machine draws this line by solving a maths problem: find the line that is closest to all data
points. This line is the model — the pattern the machine has learned. With this line, it can
predict the price of any new house.

The Maths Behind the Line (Gentle Introduction)


Every straight line follows this equation — you may have seen this in school:

y = m × x + c
y = the thing we want to predict (house price in ₹ Lakhs)
x = the input we know (house size in sq. metres)
m = slope (how much price increases per extra sq. metre)
c = intercept (base price even for a 0 sq.m house — the starting point)

From our data, if we calculate the best values, we get approximately:

Price = 0.52 × Size + (−0.9)

Let us verify this against our data:

House A: 0.52 × 50 − 0.9 = 25.1 ✓ (actual: 25)


House C: 0.52 × 100 − 0.9 = 51.1 ✓ (actual: 52)
House F: 0.52 × 200 − 0.9 = 103.1 ✓ (actual: 104)

New house (175 sq.m): 0.52 × 175 − 0.9 = 90.1 ← Our


prediction!

The machine found m = 0.52 and c = −0.9 by minimising a quantity called the loss — the total
error between its predictions and the actual prices. We will explore exactly how this works

Page 12
Machine Learning — A Complete Guide | Chapter 0

mathematically in Chapter 2 (Linear Regression). For now, just appreciate the big picture: the
machine learned a rule (the equation) from data, without anyone telling it the rule.

Page 13
Machine Learning — A Complete Guide | Chapter 0

Step 3 — Making a Prediction (Inference)


Once the model is trained (the line is drawn, the equation is found), using it is trivially simple.
You just plug in your new input and calculate the output. This is called inference.

Collect new input


1 A new house has size = 175 sq. metres.

Feed into the model


2 Price = 0.52 × 175 + (−0.9) = 90.1

Get the prediction


3 The model says: ₹90.1 Lakhs.

(Optional) Check accuracy


4 If the house actually sells for ₹92L, our error was ₹1.9L — pretty good!

⚠️ Important Caveat

Our model is only as good as our data. If we only had house sizes as input, our model
ignores important factors — location, number of bedrooms, age of building, parking
space. A better model would include all these features. This is why data quality and
feature selection are critical in ML.

Page 14
Machine Learning — A Complete Guide | Chapter 0

0.4 Machine Learning in the Real World


Let us ground everything we have learned in the applications you interact with every day —
and understand the ML happening behind the scenes.

Application 1: Your Email Spam Filter


Every email you have ever sent or received has been scanned by an ML model. Here is
exactly how the spam filter thinks:

INPUT: Incoming email



┌─────────────────────────────────────────────────────────────────

│ FEATURE EXTRACTION — converting email to numbers



│ Subject contains 'FREE': 1 (yes) or 0 (no)

│ Subject contains 'WIN': 1 or 0

│ Sender in your contacts: 1 or 0

│ Number of exclamation marks: 7

│ All-caps words count: 12

│ Contains suspicious URL: 1 or 0

└─────────────────────────────────────────────────────────────────


▼ (these numbers are fed into the ML model)

┌─────────────────────────────────────────────────────────────────

│ ML MODEL

│ (trained on millions of known spam/not-spam emails)

└─────────────────────────────────────────────────────────────────

Page 15
Machine Learning — A Complete Guide | Chapter 0



OUTPUT: SPAM (0.97 confidence) → Move to Spam folder

The model was trained on millions of emails where humans had already labelled each one
'spam' or 'not spam'. The model learned which patterns (combination of features) reliably
indicate spam — and now it applies that learning to every new email in milliseconds.

Application 2: Netflix / YouTube Recommendations


When Netflix recommends a show, it is solving a problem called collaborative filtering. Here
is the intuition:

👥 The Idea

'Users who behaved similarly to you in the past tended to like the same things. So we
will recommend to you what they liked next.'

It sounds simple — and the core idea is. But Netflix has 260 million users and 15,000
titles. Doing this at scale, in real-time, for every user simultaneously, is an enormous
engineering and ML challenge.

What ML Tracks About You Why It Matters


What you watch (and finish vs abandon) Finishing = strong signal of enjoyment
What you search for Shows interest even without watching
Time of day you watch Morning person? Late-night binge-watcher?
What you pause and rewind You liked that scene so much you
rewatched it
What you scroll past without clicking Strong negative signal
Your star ratings Explicit feedback — most reliable signal

Application 3: Google Maps — Estimating Arrival Time


When Google Maps says 'Arrive in 23 minutes', that is an ML regression model at work. The
inputs include:

Page 16
Machine Learning — A Complete Guide | Chapter 0

• Current GPS positions of thousands of other cars on the same roads (anonymised)
• Historical traffic patterns for this road, this day of the week, this time of day
• Weather conditions (rain slows traffic by roughly 15-20%)
• Special events (cricket match, concert) near the route
• Known roadworks, accidents reported by users

The model has been trained on billions of past journeys where the actual travel time was
recorded. It finds patterns — 'when these inputs look like this, travel time is typically about X
minutes' — and applies them to your current journey.

Application 4: Face ID on Your Phone


When you unlock your phone with your face, a Deep Learning model is running in under 50
milliseconds. Here is what it does:

Capture
1 The front camera takes an infrared image of your face (works in the dark too).

Detect
2 A detection model finds the face in the image and crops it.

Embed
3 A deep neural network converts your face into a list of ~128 numbers (a 'face
embedding'). This is your unique numerical face fingerprint.

Compare
It compares these 128 numbers to the stored embedding of the enrolled face
4 (yours). If the mathematical distance between the two is below a threshold →
match → unlocked.

Decision
5 If distance < threshold: UNLOCK. Else: try again or use passcode.

🔢 The 128 Numbers

Those 128 numbers capture things like: distance between eyes, nose shape, jawline
curvature, cheekbone position — but NOT in a way humans explicitly programmed. The
deep network learned on its own which facial measurements best distinguish one
person from another, by training on millions of labelled face photos.

Page 17
Machine Learning — A Complete Guide | Chapter 0

The ML Landscape — What Exists Today

Category What It Does Famous Examples


Computer Vision Understands images and Face ID, Tesla Autopilot, medical
video imaging, Google Lens
Natural Language Understands and ChatGPT, Google Translate, Siri,
Processing generates text/speech Alexa, Gmail autocomplete
Recommender Predicts what you will like Netflix, Spotify, YouTube, Amazon,
Systems Instagram
Time Series Predicts future from past Stock prices, weather, electricity
Forecasting patterns demand, supply chains
Anomaly Detection Finds the unusual in Credit card fraud, network intrusion,
normal patterns machine fault detection
Reinforcement Learns by trial and error in AlphaGo, game-playing AI, robotics, ad
Learning an environment bidding
Generative AI Creates new content (text, DALL-E, Midjourney, Suno (music),
image, audio) Claude, GPT-4

Page 18
Machine Learning — A Complete Guide | Chapter 0

0.5 Your First Machine Learning Code


Theory is essential — but nothing builds intuition like writing real code and seeing it work. We
will now write a complete, working ML program. Do not worry if every line is not perfectly clear
yet — we will explain each part.

🐍 Why Python?

Python is the dominant language for Machine Learning. Reasons:


• Clean, readable syntax — very close to plain English
• World-class ML libraries — scikit-learn, TensorFlow, PyTorch, pandas, NumPy
• Massive community — almost every ML question has been answered on Stack
Overflow

Part A — Understanding the Problem


We are going to build our house price predictor from Section 0.3 — in actual Python code. The
model will learn from 6 data points and then predict the price for a new house.

Part B — Pseudocode First (Plain English Plan)


Before writing real code, experienced programmers write pseudocode — a plain English plan
of what the code should do. This helps you think clearly before worrying about syntax.

PSEUDOCODE: House Price Predictor


═══════════════════════════════════════════════════════════

STEP 1: Set up our data


sizes ← [50, 80, 100, 120, 150, 200] ← input (X)
prices ← [25, 41, 52, 63, 78, 104] ← output (y)

STEP 2: Create a Linear Regression model


model ← new LinearRegression()

STEP 3: Train the model


[Link](sizes, prices)
// model finds best values of m and c automatically

STEP 4: Make a prediction

Page 19
Machine Learning — A Complete Guide | Chapter 0

new_house_size ← 175
predicted_price ← [Link](new_house_size)

STEP 5: Print the result


PRINT 'Predicted price for 175 sq.m house: ' +
predicted_price

Part C — The Real Python Code

Python — house_price_predictor.py
# ═══════════════════════════════════════════════════════════════
# House Price Predictor — Our First Machine Learning Program
# ═══════════════════════════════════════════════════════════════

# ── STEP 1: Import the tools we need ──────────────────────────


import numpy as np # numpy: handles numbers &
arrays
from sklearn.linear_model import LinearRegression # scikit-
learn: ML library
from [Link] import mean_squared_error, r2_score

# ── STEP 2: Our training data ─────────────────────────────────


# X = sizes (input feature), y = prices (target/label)
sizes = [Link]([50, 80, 100, 120, 150, 200]).reshape(-1,1)
prices = [Link]([25, 41, 52, 63, 78, 104]).reshape(-1,1)

# reshape(-1, 1) means: make it a column vector (1 column, many


rows)
# ML libraries expect this shape for the input X

# ── STEP 3: Create and train the model ───────────────────────


model = LinearRegression() # create a blank model
[Link](sizes, prices) # TRAIN the model — this is
where learning happens!

# .fit() automatically calculates the best m and c

# ── STEP 4: Inspect what the model learned ────────────────────


print(f"Slope (m): {model.coef_[0]:.4f}}")

Page 20
Machine Learning — A Complete Guide | Chapter 0

print(f"Intercept (c): {model.intercept_[0]:.4f}}")

# ── STEP 5: Predict for a new house ──────────────────────────


new_house = [Link]([[175]]) # 175 sq.m house
prediction = [Link](new_house)
print(f"Predicted price for 175 sq.m: ₹{prediction[0]:.2f}} Lakhs")

# ── STEP 6: Check how well the model fits ────────────────────


y_pred = [Link](sizes) # predict on training
data
r2 = r2_score(prices, y_pred) # R² score: 1.0 =
perfect
print(f"Model accuracy (R² score): {r2:.4f}}")

Part D — Understanding the Output

── OUTPUT (what you will see when you run this)


─────────────────────

Slope (m): 0.5200


Intercept (c): -0.9000

Predicted price for 175 sq.m: ₹90.10 Lakhs

Model accuracy (R² score): 0.9998

Decoding the Output — Line by Line

Output Line What It Means Good Sign?


Slope (m): 0.5200 For every extra square metre, price Makes sense! Bigger
increases by ₹0.52 Lakhs (₹52,000) houses cost more.
Intercept (c): −0.9 Mathematical starting point of the line Just a number — do not
(can be negative) over-interpret it.
Predicted price: Our model's prediction for a 175 sq.m We expected around ₹90L
₹90.10 L house — perfect!
R² score: 0.9998 How much of the variation in price the 0.9998 ≈ perfect fit for this
model explains. 1.0 = perfect. 0 = simple data!
useless.

Page 21
Machine Learning — A Complete Guide | Chapter 0

📊 What is R² (R-Squared)?

R² (pronounced 'R-squared') is a number between 0 and 1 that tells you how well your
model explains the data:

• R² = 1.0 → Perfect. Your model explains 100% of the variation. (Suspicious — usually
means overfitting!)
• R² = 0.85 → Good. Model explains 85% of the variation in the target.
• R² = 0.50 → Weak. Model explains half the variation. Improve your features.
• R² = 0.0 → Useless. No better than guessing the average every time.
• R² < 0 → Worse than useless. Your model is doing something badly wrong.

Part E — Making It a Real Experiment


Good scientists do not just run code — they experiment. Try these modifications:

Python — Experiments to Try


# EXPERIMENT 1: Add more features — does it improve the model?
# Suppose we also have number of bedrooms

# sizes = [50, 80, 100, 120, 150, 200]


# bedrooms= [ 1, 2, 2, 3, 3, 4]

# X would now be 2 columns instead of 1 (multivariate regression)


X = [Link]([[50,1],[80,2],[100,2],[120,3],[150,3],[200,4]])

# EXPERIMENT 2: What if we add a noisy / wrong data point?


# Change prices to [25, 41, 52, 63, 78, 104, 999] ← outlier!
# What happens to the R² score? To the slope?

# EXPERIMENT 3: Visualise the line (requires matplotlib)


import [Link] as plt
[Link](sizes, prices, color='blue', label='Actual')
[Link](sizes, [Link](sizes), color='red', label='Predicted
line')
[Link]('Size (sq.m)')
[Link]('Price (Lakhs)')
[Link]()
[Link]()

Page 22
Machine Learning — A Complete Guide | Chapter 0

Page 23
Machine Learning — A Complete Guide | Chapter 0

0.6 Chapter Summary


You have covered a lot of ground in this chapter. Let us lock in the key ideas before moving
on.

WHAT WE COVERED IN CHAPTER 0

0.1 Intelligence
• Intelligence = ability to learn from experience, reason, and adapt to new situations.
• Computers are faster but lack common sense; humans generalise better but are
slower and error-prone.

0.2 AI vs ML vs Deep Learning


• AI: any technique making machines mimic human intelligence (broadest term).
• ML: machines learn rules automatically from data — no manual rule-writing.
• Deep Learning: ML using multi-layered neural networks — powers ChatGPT, image
recognition, etc.

0.3 How Computers 'Think'


• All data becomes numbers. ML finds patterns in those numbers.
• The linear model y = mx + c is the simplest learned pattern.
• Training = finding best m and c. Inference = using that equation on new data.

0.4 Real-World Applications


• Spam filters, recommendations, navigation, face recognition — all ML.
• ML categories: vision, NLP, recommenders, forecasting, anomaly detection,
generative AI.

0.5 First Code


• Linear Regression in Python with scikit-learn — [Link]() trains, [Link]()
infers.
• R² score measures goodness of fit: 1.0 = perfect, 0.0 = useless.

Page 24
Machine Learning — A Complete Guide | Chapter 0

Self-Test Questions
Answer these without looking back. If you struggle, re-read that section.

# Question Hint
1 In your own words: what is the difference between AI = broad. ML = learns from
AI and Machine Learning? Give one example of data.
each.
2 Why do we say Deep Learning is a subset of ML, Think of the onion diagram.
which is itself a subset of AI?
3 A chatbot is programmed with 5,000 hand-written Check the definition of ML
rules for responding to questions. Is this AI? Is it carefully.
ML?
4 In y = mx + c, what does the slope m represent in How price changes per sq. metre.
the house price example?
5 What does an R² score of 0.72 tell you about a It explains 72% of... what?
model?
6 Name 3 things about you that Netflix's Think about what you do on the
recommendation ML model likely tracks. app.
7 Why is the reshape(-1, 1) needed in the Python ML libraries expect data in a
code for the sizes array? certain shape.

What Comes Next — Chapter 1 Preview

Chapter 1: Data — The Fuel of Machine Learning


In Chapter 1, we will go deep on data — the raw material without which ML is
impossible. We will cover:

• Types of data: numerical, categorical, text, image, time-series


• How to load and explore a real dataset using pandas
• Data cleaning — handling missing values, outliers, duplicates
• Feature engineering — turning raw data into useful ML inputs
• Train/Validation/Test splits — and why they matter
• Python: full data exploration pipeline with a real-world dataset

── End of Chapter 0 ──

Page 25

You might also like