Skip to content
truthxify
← Journal

Phase 2 — Classical ML

May 21, 2026

Continue Machine Learning Specialization(Advanced Learning Algorithms)

What I Did

Watched all the lectures in week 3 of the Advanced Learning Algorithms course(prepping for week 4)

Implemented hand written digit classification using Tensorflow(it predicts hand written digits from the image)

Went through a whole bunch of techniques to do model evaluation, validation, testing and fine tuning

What I Learned

Learned about model diagnosis, when a model performs poorly, we can do the following:

  • Collect more training data
  • Try a smaller set of features
  • Add more features
  • Add polynomial features
  • Decrease the regularization parameter λ\lambda
  • Increase λ\lambda
  • Make the model bigger
  • Train longer

Learned about splitting dataset into training, validation and testing set. Training set is a subset of the dataset we use for training, validation set is a subset we use for cross-validation and we use use it to tune hyperparameters and pick the best model from the models we have and we use testing set only once at the very end to estimate true generalization

We typically use the ratio training/validation/testing → 60%/10%/10% for smaller dataset(~10K) and 98%/1%/1% for larger dataset(millions)

It is important not to use the testing set for training or validation because the model will learn from it and we risk overfitting

Bias measures how much the model underfits:

gapbias=EtrainEbaseline\text{gap}_\text{bias} = E_\text{train} - E_\text{baseline}

Variance measures how much the model overfits:

gapvariance=EvalEtrain\text{gap}_\text{variance} = E_\text{val} - E_\text{train}

where:

EtrainE_\text{train} is the error on the training set

EvalE_\text{val} is the error on the validation set

EbaselineE_\text{baseline} is the achievable baseline error (e.g., human-level performance or best published result)

We can see from the equations above that high training error leads to high bias and low training error and high validation error leads to overfitting while high training error and even higher validation error leads to both high bias and high variance

What we want is where both training error and validation error are low.

So how can we fix high bias(underfitting)? We can do the following:

  • Add more features
  • Add polynomial features
  • Use a more complex model
  • Decrease the regularization parameter λ\lambda
  • Train longer

Note that adding more data does not fix underfitting because the model can't even learn enough from the smaller dataset we gave it

How to fix high variance(overfitting):

  • Reduce the features
  • Get more training data
  • Increase the regularization parameter λ\lambda
  • Use a simpler model

We mostly have the issue of high bias for classical ML, neural networks fixes this problem coz they learn as much as possible and for the high variance problem, we can add more training data and regularization to fix that.

Another way to inspect and visualize the model is to plot the training and validation error as a function of the training set size, we can inspect how well the model does by adding more data. Note that this is computationally expensive and its not done that much in practice

We can also add regularization to fix underfitting/overfitting, I've been talking about it since but haven't really explained it, the aim of regularization is to increase of decrease the weights.

Say the cost function is the mean squared error, if we add L2 regularization, the error becomes:

J(w,b)=1mL(y,y^)+λ2mW2J(w, b) = \frac{1}{m}\sum L(y, \hat{y}) + \frac{\lambda}{2m}\sum W^2

Tuning λ\lambda:

  • λ\lambda = 0 → no regularization. Model has freedom to overfit. High variance
  • λ\lambda small → slight regularization. Doesn't restrict model much
  • λ\lambda moderate → sweet spot
  • λ\lambda large → over regularized. All weights forced near zero. High bias

The iterative loop of ML development is:

  • Choose architecture(model type, features, hyperparameters)
  • Train the model
  • Diagnose the error
  • Use diagnostic to decide what to change
  • We can always go back to step 1

We can use error analysis to look at what the model got wrong and try to add more training data that will help the model learn better regarding what it got wrong.

Note that we don't need to add general data, we can just add specific data where its failing for it to learn more.

Error analysis needs human intervention and it only works where the human can predict what the output is like.

We can also add more data, there are ways to do this like data augmentation(good for image and audio) like generating new data by modifying training examples and we can use data synthesis to generate completely new data from artificial data inputs(used in computer vision). This is much cheaper than collecting genuine new labeled data.

We can also use the techniques of transfer learning when we have a small dataset, we can train on a related large dataset first(supervised pretraining) then fine-tune on our smaller dataset.

We can do this in two ways where the first is to fine tune the whole network(when we have more data) and the second is to train only the new output layer's weights(when we have little data)

There is also the question of fairness, bias and ethics which are the top questions most human beings are interested in regarding AI now.

Bugs & Blockers

N/A

Concepts That Need More Time

The choosing the output of the multi-class classification due to errors in calculation(using the expression for the output a instead of using a directly) actually feels a bit confusing to me for now(still haven't figured this out man)

Tomorrow

Watch week 4 of course 2 of the Machine Learning specialization

Wins

Implemented hand written digit classification using Tensorflow(it predicts hand written digits from the image)

Demystified fine tuning and serving models for inference(MLOps)