Session 02🧠

ML, DL & GenAI Overview

The big map: the four families of machine learning, how to pick an algorithm and a metric, overfitting, then Deep Learning, GenAI and LLMs.


Learning Objectives

  • βœ“Place a problem in the right family: supervised, unsupervised, semi-supervised or reinforcement
  • βœ“Pick an algorithm to match the data and a metric to match the cost of each kind of error
  • βœ“Tell underfitting from overfitting; use cross-validation to evaluate
  • βœ“Know the three main Deep Learning architectures and the conditions they need
  • βœ“Locate Generative AI, LLMs and Agents in the overall picture

The Families of Machine Learning

Machine learning extracts rules from data instead of being programmed explicitly, and splits into four families. Supervised learning works on labeled data: classification when the output is a category, regression when it is a number. Unsupervised learning finds hidden structure through clustering, anomaly detection and dimensionality reduction. Semi-supervised combines a little labeled data with a great deal of unlabeled data. Reinforcement learning learns from reward and penalty signals over time.

Algorithms & Model Selection

The supervised family: Linear Regression for continuous output, Logistic Regression for binary classification, Decision Trees when you need explainability, SVM for few samples in many dimensions, NaΓ―ve Bayes for text, plus kNN, Random Forest and XGBoost. The unsupervised family: K-means, DBSCAN, PCA. No algorithm is best for every problem β€” build a simple model as a baseline first, then add complexity.

Model Evaluation

Accuracy misleads when the classes are imbalanced: with 950 of 1000 emails legitimate, a model that always predicts "not spam" still scores 95% while learning nothing. The Confusion Matrix is the root of every metric. Precision matters when a false alarm is expensive, Recall when a miss is the costliest outcome, and F1F_1 is the harmonic mean so it is high only when both are. AUC-ROC measures class separability across the full range of thresholds.

Precision=TPTP+FPRecall=TPTP+FNF1=2β‹…Pβ‹…RP+R\text{Precision} = \frac{TP}{TP + FP} \qquad \text{Recall} = \frac{TP}{TP + FN} \qquad F_1 = 2 \cdot \frac{\text{P} \cdot \text{R}}{\text{P} + \text{R}}
Precision reads down the predicted column, Recall reads across the true-label row
Confusion Matrix β€” spam filteringPython
# 1000 emails: TP=140, FN=20, FP=30, TN=810
accuracy  = (140 + 810) / 1000   # = 95.0%
precision = 140 / (140 + 30)     # = 82.4%
recall    = 140 / (140 + 20)     # = 87.5%
f1        = 2 * precision * recall / (precision + recall)  # = 84.8%
# 95% accuracy sounds high, but 20 real spam emails still got through

Training, Overfitting & Cross-Validation

Training is the phase that adjusts weights on labeled data; inference applies the result to data never seen before. Underfitting is wrong on both sets; overfitting learns the noise too, so it looks good on train and falls apart outside. Curb overfitting with more data, L1/L2 regularization, dropout and early stopping. K-Fold rotates through K rounds and reports the mean alongside the standard deviation β€” the deviation tells you how far to trust the number.

K-Fold Cross-ValidationPython
from sklearn.model_selection import cross_val_score, train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

scores = cross_val_score(model, X, y, cv=5, scoring='accuracy')
print(f'CV Accuracy: {scores.mean():.3f} Β± {scores.std():.3f}')
# [87%, 92%, 85%, 90%, 88%] β†’ 88.4% Β± 2.4%

Deep Learning

The core difference is not the number of layers but who designs the features: traditional ML needs a human to craft them, deep learning derives them from raw data through successive layers of representation. The consequence is that traditional ML saturates as data grows while deep networks keep improving β€” given enough data and GPUs. Three foundational architectures: CNNs for images, RNNs for sequences, LSTM/GRU using gates to hold on to long-range dependencies.

Generative AI

Discriminative models learn the boundary between classes, that is P(label∣data)P(\text{label} \mid \text{data}); generative models learn the data distribution itself, so they can produce new samples. Four architectures: GANs pit a generator against a discriminator (sharp, unstable), VAEs compress into a latent space (stable, slightly blurry), Diffusion denoises step by step (currently dominant in image generation), Transformers use self-attention. Milestones: GAN 2014, Transformer 2017, GPT-3 in 2020, ChatGPT in 2022.

LLMs & Agents

An LLM is a Transformer trained on an enormous volume of text, where self-attention processes every position in a sentence in parallel rather than sequentially. Three stages produce one: pre-training for broad background knowledge, fine-tuning for specialization, and prompting to steer each individual request. Agents are the extension β€” the model is handed tools so it can query, call APIs and choose its own next action.