session: "6103-advanced-ml/2026-10-10 0926 Advance Machine Learning (2)"
title: "Advance Machine Learning"
date: "2026-10-10 09:26"
duration: "58m 23s"
language: "en"
model: "deepseek-ai/DeepSeek-V3.2"
parts: 3
transcript_chars: 41218
generated: "2026-11-23T02:07:38+05:30"
Advanced Machine Learning
Overview
This class focused on building and training neural networks for image classification, specifically using the MNIST dataset. It served as a practical introduction to deep learning workflows, connecting the theoretical concept of backpropagation from the previous class to implementation. The session covered data preprocessing, model architecture design with Keras, and the empirical, trial-and-error nature of machine learning optimization.
Learning outcomes
- Load and preprocess image data (MNIST) for neural network input.
- Design a multi-layer perceptron (MLP) architecture using Keras, including flatten, dense, and dropout layers.
- Explain the purpose of techniques like one-hot encoding, normalization, and dropout.
- Compile a model by selecting an appropriate optimizer (e.g., Adam) and loss function (e.g., categorical cross-entropy).
- Articulate why there are no fixed rules in ML/DL and why experimentation is essential.
Core concepts
Deep Learning & Multi-Layer Perceptron (MLP)
A neural network with multiple hidden layers is termed "deep learning." An MLP is a foundational type of deep network where layers are fully connected (dense). It matters because stacking layers allows the network to learn hierarchical and complex feature representations from data, moving beyond simpler models.
Data Preprocessing Pipeline
This involves preparing raw data for model consumption. Key steps for image data include resizing to a fixed resolution (e.g., 28x28), normalization (scaling pixel values to 0-1), and one-hot encoding labels. It connects directly to model performance, as well-preprocessed data leads to more stable and faster training.
Fully Connected (Dense) & Flatten Layers
A dense layer connects every neuron to all neurons in the subsequent layer. A flatten layer reshapes a 2D input (like an image) into a 1D vector. These are core architectural components for building MLPs from image inputs, defining how information flows and transforms through the network.
Regularization via Dropout
Dropout is a technique that randomly deactivates a fraction of neurons during each training iteration. It matters because it prevents overfitting, where a model performs well on training data but poorly on unseen test data, by forcing the network to learn robust features that don't rely on any single neuron.
Optimizers and Loss Functions
An optimizer (like SGD or Adam) implements the algorithm to update weights during backpropagation. A loss function (like categorical cross-entropy) quantifies the error between predictions and true labels. Their selection is crucial as they directly control how the model learns and converges during training.
Formulas and maths
- Weight Update Rule:
new weight = old weight + learning rate * derivative of J(θ) with respect to θ - Symbols:
J(θ) is the cost/loss function, θ represents the model parameters (weights), and the learning rate controls the step size. - Used: During backpropagation to iteratively adjust weights and minimize loss.
- Normalization:
pixel value / 255 - Symbols: Pixel value is the original intensity (0-255).
- Used: As a preprocessing step to scale image data to a [0, 1] range for neural network stability.
- Binary Cross-Entropy (spoken form):
y log y - (1 - y) log (1 - y) - Symbols:
y represents the predicted probability. - Used: For calculating loss in binary classification problems (two classes). (Note: Transcript was unclear; standard form is
- [y_true log(y_pred) + (1 - y_true) log(1 - y_pred)])
Worked examples
- MNIST Dataset: Contains 70,000 total images: 60,000 for training and 10,000 for testing. Each image is 28x28 pixels.
- One-Hot Encoding: For label "5", the encoded vector is
[0,0,0,0,0,1,0,0,0,0]. For label "0", it is [1,0,0,0,0,0,0,0,0,0]. - Flatten Layer: An input image of 28x28 pixels is flattened to a 1D vector of size 784 (since 28 * 28 = 784).
- Dropout Calculation: In a layer with 256 units and a dropout rate of 0.45, approximately 45% of units are dropped. Active units ≈ (1 - 0.45) * 256 = 140.8, meaning roughly 140 units remain active in that iteration.
- Weight Initialization: Weights can be initialized using a random normal distribution with a standard deviation of 0.02 (this value can be changed, e.g., to 0.04).
- Output Layer: For the 10-class MNIST classification, the final dense layer has 10 units.
Questions asked in class
- Q: What is the difference between classifier and model?
- A: For classification tasks, they are the same. "Model" is a generalized term; "classifier" is a subset used for classification.
- Q: Can we use PyTorch instead of Keras?
- A: Yes, you can use PyTorch; only the syntax differs.
- Q: Why import specific modules from Keras instead of everything?
- A: To reduce computational complexity and keep the code cleaner.
- Q: In real-world scenarios, how do we prepare data?
- A: Based on the problem, import data (e.g., using pandas), then perform data cleaning, augmentation, normalization, and resizing as needed.
- Q: Why reduce neurons in hidden layers?
- A: Start simple and use trial-and-error; increasing layers may cause overfitting. If good results come from fewer layers, avoid adding more.
- Q: What kind of data preparation is needed for images?
- A: Convert all images to a fixed resolution (e.g., 28x28), convert RGB to grayscale (single channel), and apply normalization.
- Q: Are there alternatives to one-hot encoding?
- A: Yes, such as label encoder, ordinal encoder, embedding, target encoding, frequency encoding (especially for text data).
- Q: When to choose a specific preprocessing technique?
- A: No thumb rule; use trial and error. Experiment with different preprocessing, models, and evaluation metrics.
- Q: Can embedding be done on images?
- A: Embedding is performed on numeric data; if images are converted to vectors, embedding can be applied.
- Q: Is normalization preferred for numeric data?
- A: For numeric data, normalization is commonly applied; for images, augmentation and normalization are used.
Key takeaways
- Deep learning involves neural networks with multiple hidden layers, known as Multi-Layer Perceptrons (MLPs).
- The MNIST dataset consists of 60,000 training and 10,000 test images of handwritten digits (28x28 pixels).
- One-hot encoding transforms categorical labels (like digit 5) into binary vectors for multi-class classification.
- Data preprocessing for images includes resizing to a fixed resolution, normalization (dividing pixel values by 255), and augmentation.
- A flatten layer converts a 2D image (28x28) into a 1D input vector of size 784 for a dense network.
- Dropout is a regularization technique that randomly drops a fraction of neurons (e.g., 45%) during training to prevent overfitting.
- Weight initialization often uses a random normal distribution, and the standard deviation (e.g., 0.02) is a parameter without a fixed rule.
- For multi-class classification (like MNIST), the output layer has 10 units and uses categorical cross-entropy loss.
- The Adam optimizer is often recommended as an adaptive choice for gradient descent, but experimentation is key.
- There is no single correct architecture or hyperparameter; machine learning requires a trial-and-error approach.
- Overfitting occurs when training accuracy is high (e.g., 98%) but testing accuracy is significantly lower (e.g., 70%).
- A classifier is a type of model used specifically for classification tasks.
Exam-style questions
1. Describe the steps to preprocess the MNIST dataset for input into a fully connected neural network.
- Answer Outline: Resize images to 28x28 (already done), normalize pixel values by dividing by 255 to scale to [0,1], flatten the 2D image to a 1D vector of 784 elements, and one-hot encode the integer labels into 10-dimensional binary vectors.
2. What is the purpose of a dropout layer in a neural network? Explain with a numerical example.
- Answer Outline: Dropout prevents overfitting by randomly deactivating neurons during training. For example, in a layer with 256 units and a dropout rate of 0.45, approximately 45% of units (about 115) are randomly dropped in each forward pass, leaving roughly 140 active units. This process varies each iteration.
3. You are building a classifier for MNIST. Specify the architecture decisions for the output layer and the loss function, justifying your choices.
- Answer Outline: The output layer must be a dense layer with 10 units, corresponding to the 10 digit classes (0-9). The activation function should be softmax to output a probability distribution. The loss function should be categorical cross-entropy, as it is the standard for multi-class classification problems.
Glossary
- Back propagation - A method for training neural networks by calculating gradients of the loss function with respect to weights.
- Deep Learning - A subset of machine learning using neural networks with multiple hidden layers.
- Multi-layer perceptron (MLP) - A basic feedforward neural network with multiple layers of densely connected neurons.
- Densely connected layer - A layer where each neuron is connected to every neuron in the subsequent layer.
- Keras - A high-level deep learning API for building and training models.
- Optimizer - An algorithm (e.g., Adam, SGD) that updates model weights to minimize the loss during training.
- MNIST dataset - A benchmark dataset of 70,000 handwritten digit images (28x28 pixels).
- One-hot encoding - Converting categorical labels into binary vectors where one element is 1 and others are 0.
- Data augmentation - Techniques to artificially expand a dataset (e.g., rotating, flipping images).
- Normalization - Scaling input data to a standard range (e.g., 0 to 1).
- Flatten layer - A layer that reshapes multi-dimensional input into a one-dimensional vector.
- Dropout - A regularization technique that randomly sets a fraction of input units to 0 during training.
- Overfitting - When a model learns patterns specific to the training data, reducing performance on new data.
- Stochastic Gradient Descent (SGD) - An optimizer that uses a random subset of data to compute gradient updates.
- Categorical cross-entropy - A loss function used for multi-class classification problems.
- Binary cross-entropy - A loss function used for binary classification problems.
Follow-ups
- Detailed explanation and hands-on implementation of data preprocessing steps.
- Comparison of different optimizers (SGD vs. Adam) and their practical impact on training.
- Hands-on experimentation with varying numbers of hidden layers and neurons to observe effects on performance.
- Exploration of encoding techniques beyond one-hot encoding (e.g., label encoder, embedding) for different data types.
- Clarification on the exact formula for binary cross-entropy loss.
- Further discussion on the dropout example mixing 100 and 4 neurons (transcript was unclear).
- Clarification on whether the current model uses binary or multi-class cross-entropy (transcript was contradictory).