Free Machine Learning with Python Notes, Exercises, and Solutions
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.
.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 Notes | Exercises & Python Code | Solutions |
|---|---|---|
| §§ 1.1–1.4 — What Is Machine Learning? | Exercise: PDF No separate Python starter for this lesson. | Solutions: PDF |
| §§ 1.4–2.2 — Learning as an Optimization Problem | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 2.3–2.6 — Searching a Cost Function | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 3.2–3.4 — The Gradient and Local Linear Approximation | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 3.5 — Gradient Descent | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 3.5, 3.6 — Step Size and Convergence | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 4.1, 4.2 — Second-Order Approximation | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 4.3, 4.4 — Newton’s Method in Several Variables | Exercise: PDF Python starter: PY | Solutions: PDF |
Regression
Linear regression, multivariable least squares, robust alternatives, model assessment, weighting, and probabilistic interpretation.
| Class Notes | Exercises & Python Code | Solutions |
|---|---|---|
| §§ 5.1, 5.2 — Linear Regression as Machine Learning | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 5.2 — Least Squares in Several Variables | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 5.3 — Alternatives to Least Squares | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 5.4 — Assessing a Regression Model | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 5.5, 5.9 — Weighted and Probabilistic Regression | 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 Notes | Exercises & Python Code | Solutions |
|---|---|---|
| § 6.1 — From Regression to Classification | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 6.2, 6.3 — Logistic Regression | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 6.2, 6.7 — Cross-Entropy | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 6.4–6.6 — Perceptrons and Support Vector Machines | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 6.8 — Classification Performance | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 7.1–7.4 — Multiclass Classification | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 7.5 — Softmax and Categorical Cross-Entropy | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 7.8 — Stochastic and Mini-Batch Optimization | Exercise: PDF Python starter: PY | Solutions: PDF |
Unsupervised Learning
Projection, principal component analysis, SVD, linear autoencoders, and k-means clustering.
| Class Notes | Exercises & Python Code | Solutions |
|---|---|---|
| § 8.2 — Orthogonal Projection and Data | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 8.3 — Principal Component Analysis | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 8.3 — PCA, SVD, and the Linear Autoencoder | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 8.5 — Clustering and k-Means | 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 Notes | Exercises & Python Code | Solutions |
|---|---|---|
| §§ 9.1, 9.3, 9.4 — Preparing Features | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 9.7 — Regularization and Feature Selection | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 10.1, 10.2, 10.4, 10.5 — Nonlinear Feature Maps | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 11.2–11.4, 11.7, 11.8 — Model Complexity and Generalization | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 11.4, 11.7 — Cross-Validation | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 12.1–12.6 — Kernel Methods | 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 Notes | Exercises & Python Code | Solutions |
|---|---|---|
| §§ 13.1–13.3 — Neural-Network Architecture | Exercise: PDF Python starter: PY | Solutions: PDF |
| § 13.4 — The Chain Rule and Backpropagation | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 13.5, 13.7 — Training Neural Networks | Exercise: PDF Python starter: PY | Solutions: PDF |
Trees and Ensemble Methods
Decision trees, random forests, and gradient boosting.
| Class Notes | Exercises & Python Code | Solutions |
|---|---|---|
| §§ 14.1–14.4, 14.7 — Decision Trees | Exercise: PDF Python starter: PY | Solutions: PDF |
| §§ 14.5–14.7 — Random Forests and Gradient Boosting | Exercise: PDF Python starter: PY | Solutions: PDF |