Chapter 1 · Machine Learning Foundations
What machine learning actually is, how it relates to statistics and AI, the taxonomy of learning problems, the end-to-end workflow of an ML project, and the Python toolchain this course uses — before a single model is trained.
🎯 Learning Objectives
- Define machine learning and distinguish it from traditional programming, statistics and AI
- Classify ML problems as supervised, unsupervised or reinforcement learning
- Describe the end-to-end ML workflow and the role of each dataset split
- Explain overfitting and underfitting at an intuitive level
- Set up a working Python environment with the core ML libraries
1. What Is Machine Learning?
In traditional programming, a human writes the rules and the computer applies them to data to produce answers. In machine learning, the direction reverses: the computer derives the rules from data. Arthur Samuel's classic definition calls it the field of study that gives computers the ability to learn without being explicitly programmed; Tom Mitchell's more formal version says a program learns from experience E with respect to task T and performance measure P if its performance at T, measured by P, improves with E.
Machine learning: Data + Answers → Rules
2. The Taxonomy of Machine Learning
Nearly every method in this course falls into one of three families, distinguished by what kind of "experience" the algorithm learns from.
| Family | Learns from | Typical question | Chapters |
|---|---|---|---|
| Supervised | Input–output pairs (labels) | "Predict this value / class" | 4–18 |
| Unsupervised | Unlabelled inputs | "What structure hides in this data?" | 19–22, 28–30 |
| Reinforcement | Rewards from interaction | "Which action maximises long-term reward?" | 23–24 |
3. The ML Workflow
A professional ML project is a pipeline of decisions, not a single
model.fit() call. The workflow below is the map for the whole course —
each stage gets dedicated chapters.
- Frame the question — business objective → measurable ML task
- Collect & explore the data — Chapter 2's statistics
- Preprocess — missing values, encoding, scaling, splitting (Chapter 3)
- Train candidate models — Parts II–IX
- Evaluate honestly — Chapters 10, 18, 31
- Tune & select — Chapter 31
- Deploy & monitor — Chapter 33's capstone perspective
4. Overfitting & Underfitting — First Pass
The single most important idea in machine learning: a model is judged by its performance on new, unseen data, not on the data it was trained on. A model that memorises its training set — overfitting — scores perfectly in training and fails in production. A model too simple to capture the underlying pattern — underfitting — fails everywhere. This tradeoff gets a formal treatment (bias–variance decomposition) in Chapter 6, and every chapter afterwards refers back to it.
5. Setting Up Your Python Environment
Two installation paths work for this course. Pick one — the code is identical either way.
Option A — Anaconda (recommended for a local setup)
# Install Anaconda or Miniconda, then create the course environment
conda create -n mlaz python=3.11
conda activate mlaz
# Core stack used throughout the course
pip install numpy pandas matplotlib scikit-learn
# Used from Part VII onwards
pip install nltk tensorflow xgboost
Listing 1.1 — Creating an isolated environment for the course.
Option B — Google Colab (zero installation)
Colab runs Jupyter notebooks in the browser with the entire stack pre-installed, including GPU access for Part VIII (Deep Learning). Every code listing in this book runs in Colab unchanged.
6. The Python ML Ecosystem
The core libraries this course relies on — and their current standing.
| Library | Role in this course | First used |
|---|---|---|
numpy | Numeric arrays, vectorised math | Ch 3 |
pandas | DataFrames, loading CSVs | Ch 3 |
matplotlib | Plotting and visual checks | Ch 3 |
scikit-learn | All classical ML models & metrics | Ch 3 |
statsmodels | Statistical summaries (R², p-values) | Ch 5 |
nltk | Text processing | Ch 25 |
tensorflow / Keras | Neural networks (ANN, CNN) | Ch 26 |
xgboost | Gradient boosting | Ch 32 |
The library landscape evolves quickly; the concepts in this book do not. Sections like this one carry a volatility badge and are reviewed quarterly.
🛠 Hands-On: Your First ML SessionBeginner
Before training any real model, verify your environment and take your first look at data the way an ML practitioner does. You will load a dataset, inspect its shape and summary statistics, and confirm the library versions — establishing the workflow every later chapter builds on.
Steps
- Create a new Jupyter notebook (or Colab notebook) named
ch01_first_session. - Import numpy, pandas and sklearn, and print their versions.
- Load the Chapter 3 dataset
Data.csvwith pandas and print its shape. - Call
dataset.describe()and write one sentence about what it tells you.
View Solution / Walkthrough
import numpy as np
import pandas as pd
import sklearn
print('numpy :', np.__version__)
print('pandas :', pd.__version__)
print('sklearn :', sklearn.__version__)
dataset = pd.read_csv('Data.csv')
print('Shape :', dataset.shape) # (rows, columns)
print(dataset.describe()) # count / mean / std / min / max ...
What you should see: 10 rows and 4 columns; the summary table
shows per-column counts (spot missing values when a count falls below 10),
means and spreads of the numeric columns. Note that describe()
silently drops non-numeric columns — one of many small traps pandas sets for
beginners, formalised in Chapter 3.
🎯 Key Takeaways
ML flips programming: instead of writing rules, the machine infers rules from data plus answers.
The three families — supervised, unsupervised, reinforcement — are decided by what the algorithm learns from, not by the algorithm itself.
Models are judged on unseen data. Overfitting (memorising) and underfitting (oversimplifying) bracket every model you will ever build.
The workflow — question, data, preprocess, train, evaluate, tune, deploy — is the map of this whole course.
Most project effort goes into data, not models: Part I exists because data quality decides project success.
Test Your Understanding
10 questions covering concepts, assumptions and interpretation from this chapter. Choose one answer per question, then check your answers.
Q1.Which task is a supervised learning problem?
Q2.Classifying emails as "spam" or "not spam" is an example of:
Q3.A grocery chain analyses thousands of unlabelled receipts to find products bought together. This is:
Q4.Overfitting is best described as a model that:
Q5.Which dataset split should be used for the final, unbiased performance estimate?
Q6.Which library is the standard toolkit for classical machine learning in Python?
Q7.In Mitchell's definition, a program "learns" if its performance at task T, measured by P:
Q8.Reinforcement learning algorithms improve by:
Q9.A model performs poorly on the training set AND the test set. This model is:
Q10.Which ordering reflects the ML workflow taught in this course?