session: "6103-advanced-ml/2026-10-10 0926 Advance Machine Learning"
title: "Advance Machine Learning"
date: "2026-10-10 09:26"
duration: "30m 14s"
language: "en"
model: "deepseek-ai/DeepSeek-V3.2"
parts: 1
transcript_chars: 23237
generated: "2026-11-23T02:05:45+05:30"
Advanced Machine Learning
Overview
This class focused on the practical construction and hyperparameter tuning of a Multi-Layer Perceptron (MLP) for image classification, using a dataset like MNIST (28x28 grayscale images). It covered defining model architecture with flatten, dense, and dropout layers, calculating parameters, and systematically adjusting hyperparameters like the number of neurons, layers, optimizer, batch size, and epochs. This session builds foundational skills in model development and diagnostics, connecting to broader themes of optimization, regularization, and performance evaluation in neural networks.
Learning outcomes
- Design and implement an MLP architecture using Keras/TensorFlow.
- Calculate the number of trainable parameters in a given model.
- Systematically tune hyperparameters (layers, neurons, optimizer, batch size, epochs) and interpret their impact on training accuracy.
- Identify signs of overfitting and underfitting and apply dropout as a regularization technique.
- Run and evaluate models, interpreting training logs and accuracy metrics.
Core concepts
Flatten Layer
Converts a multi-dimensional input (e.g., a 28x28 image) into a one-dimensional vector (784x1). This is necessary to connect the image pixels to the first dense (fully connected) layer of the neural network.
Dense (Fully Connected) Layer
A layer where each neuron is connected to every neuron in the previous layer. It applies a linear transformation (weights * inputs + bias) followed by a non-linear activation function. This is the core building block for learning complex patterns.
Dropout
A regularization technique that randomly disables a specified fraction of neurons during each training iteration (e.g., dropout rate of 0.1). It helps prevent overfitting by ensuring the model does not become overly reliant on specific neurons or co-adaptations.
Hyperparameter Tuning
The process of adjusting model configuration settings that are not learned during training (e.g., number of layers, neurons, optimizer type, batch size, epochs). Systematic tuning is crucial for finding a model that generalizes well to unseen data.
Overfitting and Underfitting
Overfitting occurs when a model learns the training data too well, including its noise, resulting in poor performance on new data. Underfitting occurs when a model fails to capture the underlying trend in the data. The class discussed dropout as a tool to combat overfitting.
Formulas and maths
- Input Shape for Grayscale Image:
28 x 28 x 1 - Symbols: 28 (height), 28 (width), 1 (channel for grayscale).
- Use: Defining the input tensor shape for the neural network.
- Flatten Layer Output Size:
784 x 1 - Symbols: 784 = 28 * 28.
- Use: Calculating the input size for the first dense layer.
- Parameters in a Dense Layer:
(input_size * number_of_neurons) + number_of_neurons - Symbols:
input_size is the number of inputs to the layer, number_of_neurons is the layer's size. The added number_of_neurons accounts for bias terms. - Use: Calculating the number of trainable weights and biases in a fully connected layer. Example: For a first hidden layer with 16 neurons following a flatten layer:
(784 * 16) + 16 = 12,544 + 16 = 12,560. - Batch Count:
Total training samples / Batch size - Symbols: Total training samples (e.g., 60,000 for MNIST), Batch size (e.g., 64).
- Use: Determining the number of parameter update steps per epoch. Example:
60,000 / 64 ≈ 938 batches.
Worked examples
1. Initial Model (Model 1):
- Architecture: Input(28x28x1) → Flatten → Dense(16, ReLU) → Dropout(0.1) → Dense(32, ReLU) → Dropout(0.1) → Dense(64, ReLU) → Dropout(0.1) → Dense(10, Softmax).
- Parameter Calculation (First Hidden Layer):
784 inputs * 16 neurons = 12,544 weights. Adding 16 biases gives 12,560 parameters for that layer. - Total Parameters:
15,586. - Training Result: After 10 epochs with SGD optimizer, accuracy was ~11%.
2. Increased Model Capacity:
- Modified Architecture: Added two more dense layers (128 and 256 neurons).
- Total Parameters: Increased to ~71,000.
- Training Result (10 epochs): Accuracy remained low at ~11%.
3. Increased Training Duration:
- Model: The above model (~71k parameters).
- Change: Increased epochs from 10 to 20.
- Training Result: Accuracy improved significantly to ~85%.
4. Optimizer Change:
- Model: Architecture with ~71k parameters.
- Change: Switched optimizer from SGD to Adam.
- Training Result: First epoch accuracy jumped to ~71-78%. Final accuracy after training reached ~96%.
5. Batch Size Adjustment:
- Model: Architecture with ~71k parameters, Adam optimizer.
- Change: Increased batch size from 64 to 128.
- Batch Count: Reduced from 938 to 469 per epoch.
- Training Result: Accuracy improved slightly to ~96.5%.
6. Further Capacity Increase:
- Model: Added a dense layer with 512 neurons.
- Training Result: Accuracy reached ~98%.
Questions asked in class
- Q: Can we use any number of neurons?
- A: Yes, but a common recommendation is to use powers of two (e.g., 16, 32, 64). It's up to you.
- Q: At what layer can we add dropout and how much percentage?
- A: Dropout can be applied to any layer apart from the input layer. The percentage is determined by trial and error.
- Q: What is the use of the dense layer?
- A: To connect each neuron with every neuron from the previous layer (fully connected network).
- Q: How did we decide to have three hidden layers?
- A: It's not a fixed criteria. It's based on trial and error (sometimes 2, 3, 4, or 5 layers).
- Q: What is the kernel initializer?
- A: It initializes the layer's weights randomly (e.g., from a normal distribution).
- Q: Can we use different activation functions in the hidden layer?
- A: Yes, you can use sigmoid, but it's more commonly recommended for binary classification, not multi-class.
- Q: Why should we change the model architecture instead of checking the number of epochs first?
- A: We change one thing at a time (e.g., architecture, then epochs) to isolate and understand the impact of each variable.
- Q: With incremental epochs, could accuracy saturate?
- A: Yes, sometimes accuracy reaches a plateau. Early stopping (a callback function) can be used to halt training when this happens.
- Q: Is accuracy a good choice to decide model performance?
- A: It's one parameter. Others include precision, recall, F1 score, binary cross-entropy, and categorical cross-entropy.
Key takeaways
- A Flatten layer converts a 2D image (28x28) into a 1D vector (784) for input to dense layers.
- The number of parameters in a dense layer is calculated as
(input_units * neurons) + neurons. - Simply adding more layers/neurons (increasing parameters) does not guarantee better performance if other hyperparameters (like epochs or optimizer) are not suitably adjusted.
- The choice of optimizer (e.g., Adam vs. SGD) can have a dramatic impact on training speed and final accuracy.
- Increasing the number of training epochs can significantly improve accuracy, but may lead to saturation.
- Dropout is a regularization technique applied to hidden layers to prevent overfitting by randomly disabling neurons during training.
- Batch size determines the number of samples processed before a weight update; a larger batch size reduces the number of updates per epoch.
- Hyperparameter tuning should be done systematically, changing one variable at a time to observe its effect.
- Model performance should be evaluated using multiple metrics, not just accuracy.
- Underfitting may occur with too few epochs or an insufficiently complex model, while overfitting may occur with excessive complexity without regularization.
- Early stopping is a callback technique used to halt training when validation performance stops improving.
Exam-style questions
1. Question: Given an MLP for MNIST classification with an input shape of (28, 28, 1), a Flatten layer, followed by a Dense layer with 32 neurons, calculate the total number of trainable parameters in this first Dense layer.
- Answer Outline: Flatten output size = 28*28 = 784. Parameters = (784 inputs * 32 neurons) + 32 biases = 25,088 + 32 = 25,120.
2. Question: A model's training accuracy is 99% but its validation accuracy is 70%. Name this phenomenon and suggest one technique discussed in class to address it.
- Answer Outline: This is overfitting. One technique to address it is adding Dropout layers to the network.
3. Question: You train an MLP for 10 epochs and get 15% accuracy. You then add two more hidden layers, retrain for 10 epochs, and accuracy remains ~15%. Propose the next single hyperparameter you should change to likely improve performance, and justify your choice.
- Answer Outline: Increase the number of epochs. Justification: The added model capacity (more layers) requires more training iterations (epochs) to learn effectively, as demonstrated in class when accuracy jumped from ~11% to ~85% after increasing epochs from 10 to 20.
Glossary
- Activation Function - A non-linear function applied to a neuron's output (e.g., ReLU, Softmax).
- Batch Size - The number of training samples processed before the model's internal parameters are updated.
- Dense Layer - A fully connected neural network layer.
- Dropout - A regularization technique that randomly ignores a fraction of neurons during training.
- Epoch - One complete pass through the entire training dataset.
- Flatten Layer - A layer that converts multi-dimensional input into a one-dimensional vector.
- Hidden Layer - Any layer between the input and output layers of a neural network.
- Hyperparameter - A configuration setting for a model that is set before training (e.g., number of layers, learning rate).
- Kernel Initializer - The method used to set the initial random weights of a layer.
- Optimizer - The algorithm (e.g., SGD, Adam) used to update model weights during training to minimize loss.
- Overfitting - When a model learns the training data too closely, including noise, harming performance on new data.
- Parameter (Trainable) - A weight or bias value that is learned during model training.
- Softmax - An activation function used in the output layer for multi-class classification to produce a probability distribution.
- Underfitting - When a model is too simple to capture the underlying pattern in the data.
Follow-ups
- Detailed discussion on the trade-offs between overfitting and underfitting.
- Implementation of the early stopping callback function.
- Exploration of evaluation metrics beyond accuracy (precision, recall, F1 score).
- Experimentation with a higher number of epochs (e.g., starting from 50) after building foundational understanding.
- Further analysis on using sigmoid activation in hidden layers for multi-class classification tasks.
Exam verification — corrections & additions
- Mini-batch training: the training set is split into small subsets (here
batch_size = 64, giving 938 batches for 60,000 images). Weights are updated once per batch — not once per sample, and not once per epoch. - batch size = 1 → stochastic gradient descent (SGD)
- batch size = whole data set → batch gradient descent
- 1 < batch size < N → mini-batch gradient descent
- Epoch vs batch vs iteration: 1 epoch = one full pass over the data; 1 iteration = one weight update on one batch.
- Full 80-question answer key:
C:\PORJECTX\aml-import\AML-FINAL-EXAM-ANSWER-KEY.md