Machine Learning for CybersecuritySource on GitHub

Contents

How to use this course

This page explains who the course is written for, how it is organized, how to run the labs, and what is expected of you when you practice attacks. Read it once before Unit 1.

Who it is for

The course is for readers who can already write Python and want to understand, at a graduate level, two related subjects. The first is how machine learning is applied to security problems such as intrusion, malware, phishing and fraud detection. The second is how machine learning systems are themselves attacked and defended. You might be a security analyst who wants to judge the learned tools in your environment, a software or data engineer moving into security, or a graduate reader preparing for research.

You should be comfortable with the following before you start.

Every lesson defines its notation and states the mathematics it uses, so a gap in one of these areas can be filled as you go.

How the course is organized

The course has twelve units in five parts: foundations (Units 1 to 4), deep learning (Units 5 and 6), attacking and defending machine learning (Units 7 and 8), generative models and governance (Units 9 to 11), and a capstone project (Unit 12). The contents page lists every unit with a one-line summary.

Units 1 to 11 each have three lessons, one or more labs, a set of exercises with worked solutions, and a self-check quiz. A lesson develops one topic with its definitions, equations, at least one worked example you can check by hand, figures, and citations to the sources it relies on. Questions headed "Check your understanding" appear where they belong in the text, with the answer hidden until you open it. Try each one before you look. A lab is a notebook that runs the methods of the unit on data, and the lessons quote its results. The exercises mix calculation, derivation, short coding tasks and design questions, and the quiz checks the main ideas in a few minutes. Unit 12 is a guide to planning, running and reporting a project of your own, using the evaluation checklist that the course builds up.

Expect to spend about 8 to 10 hours on each of Units 1 to 11, including the labs, the exercises and the quiz. Unit 12 takes about 2 hours for the lesson, exercises and quiz, plus the time for the project itself (about 10, 25 or 50 hours for a small, medium or large project). The units are meant to be taken in order, since later units use the measures, the dataset and the evaluation rules of Units 1 and 2. If you already know the standard supervised and unsupervised methods and basic neural networks, you can move quickly through Units 3 to 5, but do not skip Units 1 and 2.

Every number in a lesson that comes from a lab is filled in from the results file of that lab, so the text and the notebooks always agree. Numbers in worked examples and in the short code snippets of the lessons are given in the text, and you can check them with a calculator or by running the snippet.

Running the labs

Each lab card has three links: Open in Colab, which runs the notebook in your browser; Read with outputs, a static page showing the notebook as it ran when the course was built; and Notebook on GitHub. The card also states roughly how many minutes the lab takes on a laptop CPU. No lab needs a GPU.

In Google Colab

Colab is a hosted notebook service that is free with a Google account. Open a lab with its Open in Colab link, choose File, then Save a copy in Drive, so that your changes are kept, and then run the cells from the top (Runtime, then Run all, or one cell at a time with Shift and Enter). The labs load the course dataset from the course repository on GitHub when they cannot find a local copy, and the few labs that use public image datasets or pretrained models download them on first use. Colab's preinstalled library versions differ from the versions pinned for the course, so your numbers may differ from the printed ones in the last digits.

On your own computer

You need Python 3.12. Download the repository from GitHub, either with git clone or as a ZIP file, and open a terminal in its top folder. Create and activate a virtual environment, install the pinned packages, and start Jupyter.

python -m venv .venv
.venv\Scripts\activate
python -m pip install -r requirements.txt
jupyter lab

The commands above are for Windows. On macOS or Linux, create the environment with python3 -m venv .venv and activate it with source .venv/bin/activate; once it is active, the remaining commands work as shown. Then open a notebook under labs/, for example labs/unit-01/lab01-first-look.ipynb. Run it from its own folder, which Jupyter does by default, so that the relative path to data/ resolves. With the pinned versions, the labs should reproduce the printed results, apart from possible differences in the last digits on other processors or operating systems. The Python primer explains virtual environments and why the versions are pinned.

Ethics and authorization

Several units teach attacks: evading detectors, poisoning training data, extracting models, inferring membership in training sets, and injecting instructions into language models. Practice them only on systems, models and data that you own or are explicitly authorized to test. Scanning, probing or attacking a system without permission can be illegal and can cause real harm to its owners and users, whatever your intent. The attack labs in this course operate on small models that you train yourself or download for the purpose, and on synthetic or public benchmark data, and none of them is directed at any system outside your own notebook. When you move from the labs to real systems, get written authorization that states the scope, and treat any data you handle, especially personal data, according to the rules that apply to it.

Reporting errors

If you find a mistake, an unclear passage, a broken link or a lab that fails, please open an issue on the course's GitHub repository (the Source on GitHub link at the top of every page). Name the page and the section, quote the passage or the error message, and say what you expected. Corrections are welcome, and they help the next reader learn the material correctly.