Prerequisites

This book assumes a specific set of foundational skills. Use the self-assessment below to determine your readiness and identify areas for review.

Required Background

Programming (Essential)

You should be comfortable with:

  • Python fundamentals: Variables, data types, control flow, functions, classes, modules
  • Data structures: Lists, dictionaries, sets, tuples, and when to use each
  • File I/O: Reading and writing files, working with CSV and JSON
  • Object-oriented programming: Classes, inheritance, methods, properties
  • Basic debugging: Using print statements, reading tracebacks, using a debugger

Self-check: Can you write a Python class that reads a CSV file, processes the data, and writes results to a new file — without looking up syntax?

If not, we recommend completing a Python fundamentals course before starting this book. Chapters 1–5 will help you level up your Python for AI-specific tasks, but they assume basic fluency.

Mathematics (Important but Reviewable)

You should have exposure to (not necessarily mastery of):

  • Basic calculus: Derivatives, partial derivatives, chain rule. You should know that a derivative measures a rate of change and be comfortable with notation like $\frac{\partial f}{\partial x}$.
  • Linear algebra basics: Matrix multiplication, transpose, dot product. You should be able to multiply a 3×2 matrix by a 2×4 matrix and know the result is 3×4.
  • Basic probability: Conditional probability, Bayes' theorem, expected value. You should understand what $P(A|B)$ means.

Self-check: Can you compute the derivative of $f(x) = 3x^2 + 2x + 1$? Can you multiply two matrices by hand? Can you explain Bayes' theorem in one sentence?

If any of these feel unfamiliar, do not worry — Chapters 2–4 provide thorough reviews of linear algebra, calculus, and probability with an AI engineering focus. However, seeing these concepts for the first time and learning AI simultaneously will be challenging. Consider reviewing a math foundations resource first.

Statistics (Helpful)

Familiarity with these concepts will accelerate your progress:

  • Mean, median, standard deviation
  • Hypothesis testing (p-values, confidence intervals)
  • Correlation vs. causation
  • Basic distributions (normal, uniform, Bernoulli)

Chapter 4 covers statistics from an AI perspective, so prior exposure is helpful but not strictly required.

If you want to prepare before starting this book, here are targeted resources:

For Python

Resource Time Coverage
Python Tutorial (python.org) 10–15 hours Official tutorial, comprehensive
Automate the Boring Stuff (Al Sweigart) 20–30 hours Practical Python programming

For Mathematics

Resource Time Coverage
3Blue1Brown "Essence of Linear Algebra" (YouTube) 3 hours Visual intuition for linear algebra
3Blue1Brown "Essence of Calculus" (YouTube) 3 hours Visual intuition for calculus
Khan Academy Probability & Statistics 10–15 hours Interactive probability review

For General ML Context

Resource Time Coverage
Andrew Ng's Machine Learning Specialization (Coursera) 40–60 hours Broad ML foundation
fast.ai "Practical Deep Learning for Coders" 30–40 hours Top-down practical approach

Self-Assessment Quiz

Answer these questions to gauge your readiness. Score yourself honestly.

Python (5 questions)

  1. What is the output of [x**2 for x in range(5)]?
  2. What is the difference between a list and a tuple in Python?
  3. Write a function that takes a list of numbers and returns the mean and standard deviation.
  4. What does if __name__ == "__main__": do and why is it used?
  5. Explain what a decorator is and give an example use case.

Math (5 questions)

  1. Compute: $\frac{d}{dx}(x^3 - 2x^2 + 4x - 1)$
  2. Multiply: $\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \begin{bmatrix} 5 \\ 6 \end{bmatrix}$
  3. If $P(A) = 0.3$, $P(B) = 0.4$, and $P(A \cap B) = 0.1$, what is $P(A|B)$?
  4. What does the dot product of two vectors measure geometrically?
  5. What is the gradient of $f(x, y) = x^2 + 3xy + y^2$ with respect to $x$ and $y$?

Scoring

  • 8–10 correct: You are well prepared. Start with Chapter 1.
  • 5–7 correct: You are ready but will benefit from careful study of Chapters 2–5.
  • 3–4 correct: Review the recommended preparation resources, then start with Chapter 1.
  • 0–2 correct: Invest 2–4 weeks in the preparation resources before beginning this book.
Answers 1. `[0, 1, 4, 9, 16]` 2. Lists are mutable (can be changed after creation); tuples are immutable. Tuples are hashable and can be used as dictionary keys. 3. ```python import math def mean_std(nums): m = sum(nums) / len(nums) s = math.sqrt(sum((x - m)**2 for x in nums) / len(nums)) return m, s ``` 4. It checks whether the script is being run directly (not imported as a module). Code inside this block only executes when the file is the main program. 5. A decorator is a function that wraps another function to modify its behavior. Example: `@staticmethod`, `@property`, or custom timing/logging decorators. 6. $3x^2 - 4x + 4$ 7. $\begin{bmatrix} 17 \\ 39 \end{bmatrix}$ (1×5 + 2×6 = 17, 3×5 + 4×6 = 39) 8. $P(A|B) = P(A \cap B) / P(B) = 0.1 / 0.4 = 0.25$ 9. The dot product measures the product of the magnitudes of two vectors and the cosine of the angle between them: $\mathbf{a} \cdot \mathbf{b} = \|\mathbf{a}\| \|\mathbf{b}\| \cos\theta$. It indicates how aligned two vectors are. 10. $\nabla f = \left(\frac{\partial f}{\partial x}, \frac{\partial f}{\partial y}\right) = (2x + 3y, \; 3x + 2y)$

Technical Setup

Before starting Chapter 1, verify your environment:

# Python 3.10 or later
python --version

# pip is up to date
pip install --upgrade pip

# Create a virtual environment for this book
python -m venv aibook-env
source aibook-env/bin/activate  # or aibook-env\Scripts\activate on Windows

# Install all dependencies
pip install -r requirements.txt

# Quick verification
python -c "
import numpy as np
import torch
import sklearn
import transformers
print('NumPy:', np.__version__)
print('PyTorch:', torch.__version__)
print('scikit-learn:', sklearn.__version__)
print('Transformers:', transformers.__version__)
print('CUDA available:', torch.cuda.is_available())
print('Setup complete!')
"

You are ready to begin. Turn to Chapter 1.