🌍 freeCodeCamp · subject

freeCodeCamp Machine Learning with Python Syllabus

The Machine Learning with Python syllabus for freeCodeCamp in full: 5 chapters and 14 topics, every one listed below, plus 50 Machine Learning with Python flashcards with answers.

5Chapters
14Topics
50Flashcards

Machine Learning with Python syllabus: all 5 chapters

Expand any chapter to see its topics and sub-topics.

  1. Machine Learning Foundations

    2 topics
    • Supervised vs Unsupervised Learning
    • Training and Evaluation
  2. TensorFlow and Neural Networks

    3 topics
    • Tensors and Operations
    • Building Neural Networks
    • Convolutional Neural Networks
  3. Natural Language Processing

    2 topics
    • Text Preprocessing
    • Recurrent Neural Networks
  4. Reinforcement Learning

    2 topics
    • Q-Learning
    • Markov Decision Processes
  5. Certification Projects

    5 topics
    • Rock Paper Scissors
    • Cat and Dog Image Classifier
    • Book Recommendation Engine using KNN
    • Linear Regression Health Costs Calculator
    • Neural Network SMS Text Classifier

freeCodeCamp Machine Learning with Python flashcards — 50 questions with answers

  1. What is supervised learning?

    Learning from labeled data: each training example is an input paired with a correct output, and the model learns a mapping $f: X \to Y$ to predict labels for new inputs (e.g., classification, regression).

  2. What is unsupervised learning?

    Learning patterns from unlabeled data with no correct outputs given; the algorithm finds structure on its own, e.g., clustering (K-Means) or dimensionality reduction.

  3. What is the difference between classification and regression?

    Classification predicts a discrete class label (spam vs ham, cat vs dog); regression predicts a continuous numeric value (e.g., insurance cost in dollars).

  4. How does reinforcement learning differ from supervised and unsupervised learning?

    An agent interacts with an environment and learns a policy that maximizes cumulative reward. There are no labeled examples (unlike supervised) but there is explicit feedback via a reward signal (unlike unsupervised).

  5. Why is a dataset split into separate training and testing sets?

    The model fits its parameters on the training set; the test set contains unseen data, so evaluating on it measures generalization rather than memorization.

  6. What is the purpose of a validation set?

    A held-out subset used during training to tune hyperparameters and monitor overfitting after each epoch, keeping the test set reserved for the final unbiased evaluation.

  7. Define overfitting and underfitting.

    Overfitting: the model fits training data too closely (including noise) — high training accuracy but poor test accuracy. Underfitting: the model is too simple to capture the underlying pattern — poor accuracy on both sets.

  8. What is an epoch, and what happens if you train for too many epochs?

    One epoch is one complete pass of the entire training dataset through the model. Too many epochs cause overfitting: training loss keeps falling while validation loss starts rising.

  9. What is a tensor?

    A generalization of vectors and matrices to arbitrary dimensions: a rank-0 tensor is a scalar, rank-1 a vector, rank-2 a matrix, and higher ranks are $n$-dimensional arrays. Tensors are the basic data objects in TensorFlow.

  10. What are the rank (degree) and shape of a tensor?

    Rank is the number of dimensions (axes) of the tensor; shape lists the number of elements along each dimension. Example: a tensor of shape $(2, 3)$ has rank 2, with 2 rows and 3 columns.

  11. What does reshaping a tensor do, and what must be preserved?

    Reshaping rearranges the elements into a new shape (e.g., tf.reshape). The total number of elements must stay the same: shape $(2, 3)$ can become $(3, 2)$ or $(6,)$ since $2 \times 3 = 6$.

  12. In TensorFlow, what is the difference between a Variable and a constant tensor?

    A tf.Variable is mutable — its value can be changed during training (used for weights and biases); constant tensors are immutable once created.

  13. What computation does a single dense-layer neuron perform?

    A weighted sum of its inputs plus a bias, passed through an activation: $y = f\left(\sum_{i} w_{i} x_{i} + b\right)$, where $w_{i}$ are weights, $b$ is the bias, and $f$ is the activation function.

  14. Why do neural networks need nonlinear activation functions?

    Without them, stacked layers collapse into a single linear transformation, so the network could only model linear relationships. Nonlinearities (ReLU, sigmoid, tanh) let networks approximate complex functions.

  15. Give the formulas for the ReLU and sigmoid activation functions.

    ReLU: $f(x) = \max(0, x)$. Sigmoid: $\sigma(x) = \frac{1}{1 + e^{-x}}$, which squashes any input into $(0, 1)$.

  16. What does the softmax activation do, and where is it used?

    It converts a vector of raw scores into a probability distribution: $\text{softmax}(z_{i}) = \frac{e^{z_{i}}}{\sum_{j} e^{z_{j}}}$. It is used on the output layer of multi-class classifiers so outputs sum to 1.

  17. What roles do the loss function and the optimizer play in training a neural network?

    The loss function (e.g., cross-entropy, MSE) measures how far predictions are from true values; the optimizer (e.g., SGD, Adam) adjusts weights to minimize that loss using gradients computed by backpropagation.

  18. What is gradient descent?

    An optimization algorithm that repeatedly updates parameters in the direction of steepest loss decrease: $w \leftarrow w - \alpha \frac{\partial L}{\partial w}$, where $\alpha$ is the learning rate.

  19. What is backpropagation?

    The algorithm that computes the gradient of the loss with respect to every weight by applying the chain rule backward through the network, enabling gradient descent to update all layers.

  20. What is the key advantage of a convolutional layer over a dense layer for images?

    Convolutions detect local patterns with small shared filters slid across the image, so learned features are translation-invariant and require far fewer parameters than fully connected layers.

Show the other 30 Machine Learning with Python flashcards
  1. What is a filter (kernel) in a CNN, and what does it produce?

    A small matrix of trainable weights (e.g., $3 \times 3$) slid over the input; at each position it computes a dot product with the underlying patch, producing a feature map that highlights where its pattern occurs.

  2. What do stride and padding control in a convolution?

    Stride is how many pixels the filter moves each step (larger stride = smaller output). Padding ('same') adds a border of zeros so the output keeps the input's spatial size; 'valid' uses no padding and shrinks the output.

  3. What does a max pooling layer do?

    It downsamples each feature map by taking the maximum value in each window (typically $2 \times 2$), reducing spatial dimensions and computation while keeping the strongest activations.

  4. Describe the typical architecture of a CNN image classifier.

    Stacked Conv2D + ReLU + MaxPooling blocks extract increasingly abstract features, then a Flatten layer converts feature maps to a vector, followed by Dense layers and a final classification output (sigmoid or softmax).

  5. What is data augmentation and why is it used in image classification?

    Generating modified copies of training images (rotations, flips, shifts, zooms) to artificially enlarge the dataset, which reduces overfitting and improves generalization when data is limited.

  6. What is a bag-of-words representation of text, and what is its main weakness?

    It represents text by the counts of each word from a fixed vocabulary, ignoring word order. Its weakness: 'dog bites man' and 'man bites dog' get identical representations.

  7. What is word embedding in NLP?

    A learned mapping of each word to a dense vector in a lower-dimensional space where similar words have similar vectors (small angle/distance between them), unlike sparse one-hot encodings.

  8. In text preprocessing for neural networks, what do tokenization and padding accomplish?

    Tokenization converts text into integer sequences (each word/token gets an index); padding adds zeros (or truncates) so all sequences share a fixed length, allowing them to be batched into one tensor.

  9. What makes a recurrent neural network (RNN) suited to sequence data?

    It processes elements one at a time while maintaining a hidden internal state that summarizes what it has seen so far, so earlier inputs influence the processing of later ones.

  10. What is the vanishing gradient problem in simple RNNs?

    During backpropagation through time, gradients are multiplied at each step and can shrink exponentially, so weight updates for early time steps become negligible and the network fails to learn long-range dependencies.

  11. How does an LSTM improve on a simple RNN?

    It adds a cell state plus input, forget, and output gates that control what information is stored, discarded, and emitted, letting gradients flow across many time steps and capturing long-term dependencies.

  12. How does an RNN language model generate text?

    Trained to predict the next character/word given the sequence so far, it generates text by sampling from its output distribution and feeding each prediction back in as the next input, repeating step by step.

  13. What is Q-learning?

    A model-free reinforcement learning algorithm that learns the action-value function $Q(s, a)$ — the expected future reward of taking action $a$ in state $s$ — stored in a Q-table and updated from experience.

  14. Write the Q-learning update rule.

    $$Q(s, a) \leftarrow Q(s, a) + \alpha \left[ r + \gamma \max_{a'} Q(s', a') - Q(s, a) \right]$$ where $\alpha$ is the learning rate, $r$ the reward, $\gamma$ the discount factor, and $s'$ the next state.

  15. What is the exploration–exploitation tradeoff, and how does the epsilon-greedy strategy handle it?

    The agent must balance trying new actions (exploration) against using known good actions (exploitation). Epsilon-greedy picks a random action with probability $\epsilon$ and the best-known action with probability $1 - \epsilon$, usually decaying $\epsilon$ over time.

  16. What does the discount factor $\gamma$ control in reinforcement learning?

    How much future rewards are worth relative to immediate ones, with $0 \leq \gamma \leq 1$: $\gamma$ near 0 makes the agent myopic; $\gamma$ near 1 makes it value long-term reward. Return: $G_{t} = \sum_{k=0}^{\infty} \gamma^{k} r_{t+k+1}$.

  17. What are the components of a Markov Decision Process (MDP)?

    A tuple $(S, A, P, R, \gamma)$: states $S$, actions $A$, transition probabilities $P(s' \mid s, a)$, reward function $R$, and discount factor $\gamma$.

  18. What is the Markov property?

    The future depends only on the current state and action, not the full history: $P(s_{t+1} \mid s_{t}, a_{t}, s_{t-1}, \ldots) = P(s_{t+1} \mid s_{t}, a_{t})$.

  19. In an MDP, what is a policy and what makes a policy optimal?

    A policy $\pi(s)$ maps each state to an action (or distribution over actions). The optimal policy $\pi^{*}$ maximizes expected cumulative discounted reward from every state; with Q-learning it is $\pi^{*}(s) = \arg\max_{a} Q(s, a)$.

  20. In the freeCodeCamp Rock Paper Scissors project, what must your player achieve, and why can't it play randomly?

    It must win at least 60% of games against each of four bots (over 1000 games). Random play yields only about 50% win rate against exploitable bots, so the player must detect and exploit each opponent's pattern.

  21. What general strategy beats the pattern-based bots in the Rock Paper Scissors project?

    Track the opponent's move history (e.g., frequency of recent n-grams of moves), predict their most likely next move, and play the move that beats it — adapting as the opponent's pattern changes.

  22. In the Cat and Dog Image Classifier project, what network type and output layer are used, and what accuracy is required?

    A CNN (Conv2D + MaxPooling blocks, then dense layers) with a single sigmoid output unit for binary classification; predictions above/below a 0.5 threshold map to dog/cat. Required test accuracy: at least 63% (70% for extra credit).

  23. What does ImageDataGenerator (with flow_from_directory) provide in the Cat and Dog project?

    It loads images in batches from directory structure, rescales pixel values (e.g., multiply by $\frac{1}{255}$ to get $[0,1]$), resizes them to a fixed size, and can apply random augmentation transforms on the fly.

  24. Why are pixel values normalized from $[0, 255]$ to $[0, 1]$ before training?

    Small, consistent input scales keep gradients well-behaved, speeding up and stabilizing training; large raw values can cause unstable updates and slow convergence.

  25. How does the Book Recommendation Engine use K-Nearest Neighbors to recommend books?

    Each book is a vector of user ratings in a sparse user–book matrix; sklearn's NearestNeighbors (cosine metric) finds the books whose rating vectors are closest to the query book, and those neighbors (with their distances) are returned as recommendations.

  26. Why are users and books with few ratings filtered out in the Book Recommendation project?

    Users with fewer than 200 ratings and books with fewer than 100 ratings are removed for statistical significance — vectors with almost no ratings give unreliable, noisy distances and meaningless neighbors.

  27. What is cosine similarity between two vectors?

    $$\cos\theta = \frac{\vec{a} \cdot \vec{b}}{\lVert \vec{a} \rVert \, \lVert \vec{b} \rVert}$$ It measures the angle between vectors regardless of magnitude: 1 means same direction, 0 means orthogonal (no similarity).

  28. What is the linear regression model equation for predicting a value from several features?

    $$\hat{y} = w_{1} x_{1} + w_{2} x_{2} + \cdots + w_{n} x_{n} + b$$ Training finds the weights $w_{i}$ and bias $b$ that minimize the prediction error (e.g., mean squared error) on the training data.

  29. In the Health Costs Calculator project, how must categorical data be handled, how is the data split, and what error is required?

    Categorical features (sex, smoker, region) are converted to numbers (label or one-hot encoding); 80% of the data trains the model and 20% tests it; the model must reach mean absolute error under \$3500. MAE: $\frac{1}{n} \sum_{i=1}^{n} \lvert y_{i} - \hat{y}_{i} \rvert$.

  30. Outline the pipeline of the Neural Network SMS Text Classifier.

    Tokenize each SMS into integer sequences and pad to fixed length; feed through an Embedding layer, then a recurrent/pooling layer and dense layers to a sigmoid output giving the probability of 'spam' (vs 'ham', i.e., normal messages); classify by thresholding at 0.5.

freeCodeCamp Machine Learning with Python FAQ

What is in the freeCodeCamp Machine Learning with Python syllabus?

freeCodeCamp Machine Learning with Python is split into 5 chapters: Machine Learning Foundations, TensorFlow and Neural Networks, Natural Language Processing, Reinforcement Learning and Certification Projects. Together they contain 14 topics.

How many chapters are in freeCodeCamp Machine Learning with Python?

5 chapters, containing 14 topics. The largest chapter is Certification Projects, with 5 topics.

Are there flashcards for freeCodeCamp Machine Learning with Python?

Yes — a 50-card Machine Learning with Python deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.