Free Machine Learning with Python Notes, Exercises, and Solutions

Teaching

I have a license to teach mathematics at the secondary level in the state of Minnesota.

Minnesota State Teaching License

These materials develop machine learning from a mathematical point of view while introducing Python as a tool for computation, experimentation, visualization, and implementation. The class notes emphasize the mathematics and algorithms; the exercises ask you to work with those ideas directly; and the Python starter scripts provide a bridge from the mathematics to executable code.

How the Python files fit into the course: When a lesson has a Python starter script, first work through the corresponding class notes and exercise sheet. Download the .py file from the middle column and use it alongside the exercise. The starter scripts are scaffolds rather than replacements for the mathematical work: comments and partially completed code guide you through implementing, testing, and visualizing methods developed in the notes. Complete the mathematical work and the associated Python work before consulting the solutions.

A PY badge appears whenever a separate Python starter script is available. Some lessons do not require one. The course is organized into expandable topic units below, following the same notes/exercises/solutions structure used elsewhere on this site.

Available Formats: PDF PY

Foundations and Optimization

What machine learning is, optimization viewpoints, gradient methods, second-order approximation, and Newton’s method.

Class NotesExercises & Python CodeSolutions
§§ 1.1–1.4 — What Is Machine Learning?
PDF
Exercise: PDF
No separate Python starter for this lesson.
Solutions: PDF
§§ 1.4–2.2 — Learning as an Optimization Problem
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 2.3–2.6 — Searching a Cost Function
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 3.2–3.4 — The Gradient and Local Linear Approximation
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 3.5 — Gradient Descent
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 3.5, 3.6 — Step Size and Convergence
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 4.1, 4.2 — Second-Order Approximation
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 4.3, 4.4 — Newton’s Method in Several Variables
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
Regression

Linear regression, multivariable least squares, robust alternatives, model assessment, weighting, and probabilistic interpretation.

Class NotesExercises & Python CodeSolutions
§§ 5.1, 5.2 — Linear Regression as Machine Learning
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 5.2 — Least Squares in Several Variables
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 5.3 — Alternatives to Least Squares
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 5.4 — Assessing a Regression Model
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 5.5, 5.9 — Weighted and Probabilistic Regression
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
Classification

Binary and multiclass classification, logistic and cross-entropy losses, perceptrons, support vector machines, performance metrics, and mini-batch optimization.

Class NotesExercises & Python CodeSolutions
§ 6.1 — From Regression to Classification
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 6.2, 6.3 — Logistic Regression
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 6.2, 6.7 — Cross-Entropy
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 6.4–6.6 — Perceptrons and Support Vector Machines
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 6.8 — Classification Performance
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 7.1–7.4 — Multiclass Classification
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 7.5 — Softmax and Categorical Cross-Entropy
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 7.8 — Stochastic and Mini-Batch Optimization
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
Unsupervised Learning

Projection, principal component analysis, SVD, linear autoencoders, and k-means clustering.

Class NotesExercises & Python CodeSolutions
§ 8.2 — Orthogonal Projection and Data
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 8.3 — Principal Component Analysis
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 8.3 — PCA, SVD, and the Linear Autoencoder
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 8.5 — Clustering and k-Means
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
Features, Generalization, and Kernels

Feature preparation and selection, nonlinear feature maps, model complexity, cross-validation, and kernel methods.

Class NotesExercises & Python CodeSolutions
§§ 9.1, 9.3, 9.4 — Preparing Features
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 9.7 — Regularization and Feature Selection
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 10.1, 10.2, 10.4, 10.5 — Nonlinear Feature Maps
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 11.2–11.4, 11.7, 11.8 — Model Complexity and Generalization
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 11.4, 11.7 — Cross-Validation
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 12.1–12.6 — Kernel Methods
PDF
Exercise: PDF
No separate Python starter for this lesson.
Solutions: PDF
Neural Networks

Network architecture, the chain rule, backpropagation, and practical neural-network training.

Class NotesExercises & Python CodeSolutions
§§ 13.1–13.3 — Neural-Network Architecture
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§ 13.4 — The Chain Rule and Backpropagation
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 13.5, 13.7 — Training Neural Networks
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
Trees and Ensemble Methods

Decision trees, random forests, and gradient boosting.

Class NotesExercises & Python CodeSolutions
§§ 14.1–14.4, 14.7 — Decision Trees
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF
§§ 14.5–14.7 — Random Forests and Gradient Boosting
PDF
Exercise: PDF
Python starter: PY
Solutions: PDF