CSE273Semester 4 • 3 CreditsCore Subjects

CSE273

Course study material, comprehensive notes, subjective model answers, and practice MCQs for CSE273 - CSE273.

Syllabus PDF
6 Units • Notes • Model Answers • MCQs
Select Course Unit (6 Units)
Active: Unit 1
Unit 1:Unit 1: Machine Learning Foundation
35 min•High-Yield Unit Guide

Unit 1: Machine Learning Foundation

Unit 1 Exam Focus & Core Takeaways

Review the core definitions, standard architectures, and syntax patterns below. Pay special attention to sections highlighted with bullet points for your mid-term and end-term subjective questions.

Unit 1: Machine Learning Foundation

1. Introduction to Machine Learning and Artificial Intelligence

The Spectrum of AI, ML, and Deep Learning

Modern computational intelligence spans a nested hierarchy of paradigms:

  • Artificial Intelligence (AI): The overarching academic discipline and engineering field dedicated to creating systems capable of performing tasks that historically required human cognition. This includes symbolic reasoning, knowledge representation, expert systems, planning, natural language processing, computer vision, and robotics.
  • Machine Learning (ML): A core subfield of Artificial Intelligence formulated on the premise that computational models can learn patterns, representations, and decision rules directly from empirical data without being explicitly programmed with deterministic if-else rules.
  • Deep Learning (DL): A specialized subset of Machine Learning centered around multi-layered Artificial Neural Networks (ANNs). Deep architectures automatically extract hierarchical feature representations from high-dimensional unstructured inputs such as raw pixels, audio waveforms, and raw text.
  • Data Science: An interdisciplinary domain synthesizing machine learning, applied statistics, data engineering, data visualization, and domain expertise to extract actionable insights and predictive signals from noisy, structured, and unstructured data.
CODE
+-----------------------------------------------------------+
| Artificial Intelligence (AI)                              |
|   +---------------------------------------------------+   |
|   | Machine Learning (ML)                             |   |
|   |   +-------------------------------------------+   |   |
|   |   | Deep Learning (DL)                        |   |   |
|   |   |   (Multi-layer Neural Networks)           |   |   |
|   |   +-------------------------------------------+   |   |
|   +---------------------------------------------------+   |
+-----------------------------------------------------------+

Traditional Programming vs. Machine Learning Paradigm

The fundamental shift introduced by machine learning lies in the inversion of data flow and rule generation:

  • Traditional Programming (Symbolic / Rule-Based Paradigm):

    • Human software engineers write explicit logic, algorithms, and business rules.
    • The computer takes Input Data and executes human-authored Rules to produce Output Answers.
    • Limitation: Fails on complex perceptual tasks (e.g., face recognition, speech-to-text) where formulating exhaustive explicit rules is mathematically or linguistically intractable.
  • Machine Learning Paradigm:

    • The computational framework takes Input Data paired with observed Outputs / Answers (or intrinsic structural signals).
    • An optimization algorithm adjusts the parameters of a mathematical hypothesis function to infer the underlying Rules / Mapping Function (f:X→Yf: X \to Y).
    • Once learned, this generalized model processes novel, unseen data inputs to predict outputs accurately.
CODE
Traditional Programming:
  [ Data ]  +  [ Rules / Code ]  ----->  [ Output Answers ]

Machine Learning:
  [ Data ]  +  [ Output Answers ] ----->  [ Learned Rules / Model Parameters ]

2. Formal Definition of Machine Learning: Tom Mitchell's Framework

In 1997, computer scientist Tom Mitchell provided the foundational formal engineering definition of a learning algorithm:

"A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E."

The Triad: ⟨T,P,E⟩\langle T, P, E \rangle

  1. Task (TT): The specific operational objective the machine must execute. It is not the learning process itself, but the operational capability being acquired.
    • Examples:
      • Object classification in satellite imagery.
      • Machine translation from German to English.
      • Autonomous vehicular path planning and lane keeping.
      • Credit default probability estimation.
  2. Performance Measure (PP): The quantitative evaluation metric assessing how competently the model performs the assigned task. PP must be measured on independent test data unseen during training.
    • Examples:
      • Accuracy, Precision, Recall, F1F_1-score for classification.
      • Mean Squared Error (MSE), Mean Absolute Error (MAE), R2R^2 score for regression.
      • Area Under ROC Curve (ROC-AUC) for probabilistic ranking.
      • Win rate / cumulative reward in reinforcement learning agents.
  3. Experience (EE): The empirical data stream or interactive environment iterations provided to the learning mechanism.
    • Supervised Learning: A collection of labeled feature-target pairs (x(i),y(i))(x^{(i)}, y^{(i)}).
    • Unsupervised Learning: An unlabeled dataset of raw vectors {x(i)}\{x^{(i)}\}.
    • Reinforcement Learning: A sequence of interactive transitions consisting of states, actions, immediate rewards, and next states (st,at,rt,st+1)(s_t, a_t, r_t, s_{t+1}).

Exemplar Mitchell Triad Formulations:

  • Spam Email Filtering:
    • Task (TT): Classify incoming email messages as spam or legitimate (ham).
    • Performance Measure (PP): Classification accuracy or FβF_\beta score (heavily penalizing false spam classifications).
    • Experience (EE): A historical database of user-labeled spam and ham emails.
  • Autonomous Vehicle Steering:
    • Task (TT): Predict optimal steering wheel angle and throttle control on paved roadways.
    • Performance Measure (PP): Average distance traveled without human safety intervention; root mean square deviation from road center.
    • Experience (EE): Telemetry data from human driving logs, camera feeds, LiDAR point clouds, and simulator interactions.

3. Paradigms of Machine Learning

Machine learning problems are categorized into distinct operational paradigms based on the nature of available supervision and the feedback mechanism.

CODE
                          Machine Learning
                                 |
     +-------------------+-------+-------+--------------------+
     |                   |               |                    |
Supervised         Unsupervised    Semi-Supervised      Reinforcement
 Learning            Learning        Learning             Learning
(Labeled Data)    (Unlabeled)    (Small Labeled +      (Reward Feedback)
 - Regression      - Clustering   Large Unlabeled)     - Policy Search
 - Classification  - Dim Reduction                     - Value Functions

1. Supervised Learning

In supervised learning, the training algorithm receives a dataset D={(x(1),y(1)),(x(2),y(2)),…,(x(N),y(N))}\mathcal{D} = \{(x^{(1)}, y^{(1)}), (x^{(2)}, y^{(2)}), \dots, (x^{(N)}, y^{(N)})\}, where each instance x(i)∈RDx^{(i)} \in \mathbb{R}^D is a DD-dimensional feature vector and y(i)y^{(i)} is the corresponding ground-truth supervisor label.

  • Regression: The target variable yy is continuous (y∈Ry \in \mathbb{R}). The algorithm models an underlying continuous functional surface.
    • Applications: Housing price valuation, stock market volatility forecasting, battery degradation lifespan estimation.
    • Standard Algorithms: Ordinary Least Squares (OLS), Ridge/Lasso Regression, Support Vector Regression (SVR), Gradient Boosted Trees (XGBoost, LightGBM).
  • Classification: The target variable yy is categorical / discrete (y∈{C1,C2,…,CK}y \in \{C_1, C_2, \dots, C_K\}).
    • Binary Classification: y∈{0,1}y \in \{0, 1\} (e.g., medical pathology detection: benign vs. malignant).
    • Multiclass Classification: y∈{1,2,…,K}y \in \{1, 2, \dots, K\} where an instance belongs to exactly one of KK mutually exclusive classes (e.g., MNIST digit recognition 0–9).
    • Multilabel Classification: An instance may simultaneously belong to multiple non-exclusive tags (e.g., tagging a news article with "Economics", "Technology", and "Politics").

2. Unsupervised Learning

In unsupervised learning, the training dataset D={x(1),x(2),…,x(N)}\mathcal{D} = \{x^{(1)}, x^{(2)}, \dots, x^{(N)}\} contains only feature representations without external labels or feedback. The model must discover latent structures, clusters, densities, or low-dimensional manifolds.

  • Clustering: Partitioning heterogeneous data points into homogeneous subsets (clusters) such that intra-cluster similarity is maximized and inter-cluster similarity is minimized.
    • Algorithms: K-Means, Hierarchical Agglomerative Clustering, DBSCAN, Gaussian Mixture Models (GMMs).
    • Applications: Customer market segmentation, document categorization, genomic sequence grouping.
  • Dimensionality Reduction: Transforming data from a high-dimensional feature space RD\mathbb{R}^D to a lower-dimensional latent space Rd\mathbb{R}^d (d≪Dd \ll D) while preserving maximal statistical variance or topological neighborhood geometry.
    • Algorithms: Principal Component Analysis (PCA), t-Distributed Stochastic Neighbor Embedding (t-SNE), Uniform Manifold Approximation and Projection (UMAP), Autoencoders.
    • Applications: Feature decorrelation, computational speedup, data visualization in 2D/3D.
  • Density Estimation & Anomaly Detection: Modeling the underlying probability density function p(x)p(x) to identify outliers falling in low-density regimes.
    • Algorithms: Isolation Forests, One-Class SVM, Kernel Density Estimation (KDE).
    • Applications: Credit card fraud interception, industrial machinery anomaly alarms.

3. Semi-Supervised and Self-Supervised Learning

  • Semi-Supervised Learning: Bridges the gap between supervised and unsupervised learning when acquiring labeled data is prohibitively expensive or time-consuming (e.g., CT scan annotations by radiologists), while unlabeled data is abundant. Uses a small set of labeled examples alongside a large corpus of unlabeled examples via pseudo-labeling, consistency regularization, or graph-based Laplacian propagation.
  • Self-Supervised Learning: A modern paradigm where the data itself provides supervision without human annotation. The system withholds a subset of the input (e.g., masking words in a sentence, hiding image patches) and trains the network to predict the withheld portions (pretext task). This pre-trained representation is subsequently fine-tuned on downstream tasks.
    • Foundations of Modern LLMs: BERT masked language modeling, GPT autoregressive next-token prediction, SimCLR contrastive vision learning.

4. Reinforcement Learning (RL)

Reinforcement Learning models the interaction between an autonomous Agent and a dynamic, stochastic Environment formalized mathematically as a Markov Decision Process (MDP) denoted by the tuple ⟨S,A,P,R,γ⟩\langle \mathcal{S}, \mathcal{A}, \mathcal{P}, \mathcal{R}, \gamma \rangle:

  • S\mathcal{S}: Set of all valid environment states.
  • A\mathcal{A}: Set of all valid actions the agent can take.
  • P(s′∣s,a)\mathcal{P}(s' | s, a): State transition probability distribution.
  • R(s,a,s′)\mathcal{R}(s, a, s'): Reward function generating scalar feedback rt∈Rr_t \in \mathbb{R}.
  • γ∈[0,1)\gamma \in [0, 1): Discount factor balancing immediate vs. future long-term rewards.
    The agent's objective is to discover an optimal policy π∗(a∣s)\pi^*(a | s) that maximizes the expected cumulative discounted return Gt=∑k=0∞γkrt+k+1G_t = \sum_{k=0}^{\infty} \gamma^k r_{t+k+1}.
  • Applications: Game playing (AlphaGo, Dota 2 OpenAI Five), robotic arm manipulation, algorithmic high-frequency trading, autonomous navigation.

4. Taxonomic Distinctions in Machine Learning Models

Parametric vs. Non-Parametric Models

DimensionParametric ModelsNon-Parametric Models
Parameter CountFixed, finite number of parameters independent of training sample size NN.Parameter count grows dynamically with training sample size NN.
Functional AssumptionStrong inductive assumption regarding the mathematical form of f(X)f(X) (e.g., linear, quadratic).Makes minimal or flexible functional assumptions about f(X)f(X).
Computational FootprintExtremely fast inference; compact memory footprint (only stores parameter weights θ\theta).Inference can be computationally heavy; often requires retaining all or a significant portion of training instances in memory.
Risk ProfileHigh bias if the parametric assumption is flawed; low variance.Low bias; susceptible to high variance (overfitting) if not properly regularized.
Representative ExamplesLinear Regression, Logistic Regression, Linear Discriminant Analysis (LDA), Multilayer Perceptron with fixed architecture.K-Nearest Neighbors (KNN), Decision Trees, Random Forests, Support Vector Machines with RBF kernel, Gaussian Processes.

Generative vs. Discriminative Models

CODE
Generative:      Models joint distribution P(X, Y) = P(X | Y) * P(Y)
                 Can generate synthetic sample features X given class Y.

Discriminative:  Models conditional distribution P(Y | X) directly
                 Learns the decision boundary separating classes directly.
  • Discriminative Models:
    • Focus strictly on predicting the label YY given the observed features XX: P(Y∣X)P(Y | X).
    • They parameterize the decision boundary directly without wasting modeling capacity on explaining how features XX were generated.
    • Advantages: Typically achieve superior classification accuracy on discriminative tasks; robust to noisy, non-informative input features.
    • Examples: Logistic Regression, Support Vector Machines (SVM), Conditional Random Fields (CRFs), Neural Network Classifiers, Boosting/Tree models.
  • Generative Models:
    • Model the joint probability distribution P(X,Y)=P(X∣Y)P(Y)P(X, Y) = P(X | Y) P(Y), or the feature distribution P(X)P(X) in unsupervised settings.
    • By applying Bayes' theorem, they derive posterior probabilities:
      P(Y=k∣X)=P(X∣Y=k)P(Y=k)∑jP(X∣Y=j)P(Y=j)P(Y=k | X) = \frac{P(X | Y=k) P(Y=k)}{\sum_{j} P(X | Y=j) P(Y=j)}
    • Advantages: Can generate novel synthetic samples X∼P(X∣Y)X \sim P(X | Y); handle missing feature values gracefully; integrate prior domain knowledge via P(Y)P(Y).
    • Examples: Naive Bayes classifiers, Linear Discriminant Analysis (LDA), Gaussian Mixture Models (GMM), Hidden Markov Models (HMM), Variational Autoencoders (VAE), Generative Adversarial Networks (GAN), Diffusion Models.

5. Inductive Bias and The "No Free Lunch" Theorem

Inductive Bias

An algorithm that learns from finite observations must generalize to unseen cases. To prefer one hypothesis over another when multiple hypotheses fit the training observations identically, an algorithm must possess an Inductive Bias—a set of implicit or explicit prior assumptions about the nature of the target function.

  • Examples of Inductive Biases:
    • Linear Regression: Assumes the relationship between features and target is strictly linear and errors are normally distributed.
    • K-Nearest Neighbors: Assumes that instances close to each other in feature space according to a metric (e.g., Euclidean distance) share identical or similar output labels (smoothness / locality bias).
    • Decision Trees: Prefers smaller, shallower trees (Occam's razor / axis-aligned orthogonal partitions).
    • Convolutional Neural Networks (CNNs): Incorporates translation invariance and spatial locality biases (neighboring pixels are correlated).
    • Recurrent Neural Networks (RNNs): Incorporates temporal invariance and sequential dependency biases.

The No Free Lunch (NFL) Theorem

Formulated by David Wolpert and William Macready (1997), the No Free Lunch Theorem states:

If all possible data-generating distributions are considered equally likely, no single machine learning algorithm outperforms any other (even a random guessing baseline) when evaluated over all possible problems.

Core Engineering Implication: There is no universal "best" machine learning algorithm. An algorithm performs well on a specific real-world domain precisely because its inductive bias matches the structural characteristics of that domain. Engineering success requires analyzing domain characteristics and selecting/tuning algorithms whose inductive biases align with the problem.


6. Mathematical and Computational Foundations: NumPy for Machine Learning

NumPy (Numerical Python) is the universal foundational array-computing library in scientific Python, powering libraries such as Pandas, Scikit-Learn, PyTorch, and TensorFlow.

1. The ndarray Object Architecture

The fundamental object in NumPy is the ndarray (N-dimensional array):

  • A contiguous, homogeneous memory block storing elements of a uniform data type (dtype such as int32, float64, bool).
  • Strides: A tuple of byte increments needed to step from one element to the next along each dimension. Strides enable rapid slicing, reshaping, and transposition without copying underlying data buffers (zero-copy views).
  • Contiguity: Arrays can be stored in row-major order (C-contiguous) or column-major order (Fortran-contiguous).
python
import numpy as np

# Creating 1D and 2D arrays
arr_1d = np.array([1.5, 2.7, 3.9], dtype=np.float64)
arr_2d = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.int32)

print("Shape:", arr_2d.shape)        # (2, 3) -> 2 rows, 3 columns
print("Dimensions:", arr_2d.ndim)    # 2
print("Data Type:", arr_2d.dtype)    # int32
print("Item size (bytes):", arr_2d.itemsize)  # 4 bytes per element
print("Strides:", arr_2d.strides)    # (12, 4) -> 12 bytes to jump row, 4 bytes to jump col

2. Array Creation Routines

python
# Zeros, Ones, and Constants
zeros_mat = np.zeros((3, 4), dtype=np.float32)
ones_mat = np.ones((2, 5), dtype=np.float64)
full_mat = np.full((3, 3), fill_value=7.0)

# Identity and Diagonal Matrices
eye_mat = np.eye(4)                  # 4x4 Identity matrix
diag_mat = np.diag([2.0, 5.0, 9.0])  # Diagonal matrix with specified diagonal elements

# Sequences
seq_range = np.arange(0, 10, 2)      # array([0, 2, 4, 6, 8])
lin_space = np.linspace(0.0, 1.0, 5) # 5 evenly spaced numbers: [0., 0.25, 0.5, 0.75, 1.]

3. Vectorization and Broadcasting Rules

Vectorization eliminates explicit Python for loops by executing element-wise operations through pre-compiled C routines, achieving 10x–100x speedups.

Broadcasting describes how NumPy handles element-wise operations between arrays of differing shapes.

Formal Broadcasting Rules:

Two dimensions are compatible for broadcasting if and only if:

  1. They are equal in size, OR
  2. One of the dimensions is exactly 1.

If the arrays differ in total number of dimensions, the array with fewer dimensions is left-padded with dimensions of size 1 until both have matching dimensions.

python
# Broadcasting Example: Normalizing a feature matrix
X = np.array([[10.0, 20.0, 30.0],
              [40.0, 50.0, 60.0]])  # Shape (2, 3)

# Column-wise mean
mean_vec = np.mean(X, axis=0)       # Shape (3,) -> broadcasts to (1, 3) -> expands to (2, 3)
std_vec = np.std(X, axis=0)         # Shape (3,)

# Standardizing features: (X - mu) / sigma
X_scaled = (X - mean_vec) / std_vec
print("Scaled Matrix:\n", X_scaled)

4. Matrix Multiplication and Linear Algebra Operations

In machine learning, matrix operations form the computational backbone of forward and backward passes.

  • Element-wise multiplication: A * B (requires broadcastable shapes).
  • Matrix dot product: np.dot(A, B) or the infix operator A @ B (requires inner dimensions to match: (m×k)@(k×n)→(m×n)(m \times k) @ (k \times n) \to (m \times n)).
python
A = np.array([[1, 2],
              [3, 4]])  # Shape (2, 2)

B = np.array([[5, 6],
              [7, 8]])  # Shape (2, 2)

# Element-wise product (Hadamard product)
elem_prod = A * B
# Result: [[5, 12], [21, 32]]

# Matrix Dot Product
mat_mult = A @ B
# Calculation:
# [1*5 + 2*7, 1*6 + 2*8] = [19, 22]
# [3*5 + 4*7, 3*6 + 4*8] = [43, 50]
print("Matrix Product:\n", mat_mult)

# Transposition and Inversion
A_T = A.T                           # Transpose
A_inv = np.linalg.inv(A)            # Matrix Inverse (A @ A_inv = I)
A_det = np.linalg.det(A)            # Determinant: (1*4 - 2*3) = -2.0

5. Random Sampling and Reproducibility

Reproducibility is paramount in scientific machine learning pipelines (train-test splits, weight initialization, stochastic sampling).

  • Modern NumPy utilizes the numpy.random.Generator interface via np.random.default_rng(seed).
python
# Modern recommended RNG instantiation
rng = np.random.default_rng(seed=42)

# Standard Normal Distribution N(0, 1)
normal_samples = rng.standard_normal(size=(4, 3))

# Uniform Distribution U(low, high)
uniform_samples = rng.uniform(low=0.0, high=10.0, size=(5,))

# Random Permutation / Shuffling
indices = np.arange(10)
shuffled_indices = rng.permutation(indices)

7. Machine Learning Workflow Lifecycle

A complete end-to-end machine learning system follows a structured engineering pipeline:

CODE
+--------------------+      +--------------------+      +--------------------+
| Problem Definition | ---> | Data Collection    | ---> | Data Cleaning &    |
| & Success Metric   |      | & Ingestion        |      | Preprocessing      |
+--------------------+      +--------------------+      +--------------------+
                                                                   |
                                                                   v
+--------------------+      +--------------------+      +--------------------+
| Model Evaluation   | <--- | Model Training &   | <--- | Feature            |
| & Error Analysis   |      | Hyperparam Tuning  |      | Engineering        |
+--------------------+      +--------------------+      +--------------------+
          |
          v
+--------------------+      +--------------------+
| Deployment & Model | ---> | Monitoring &       |
| Serving (API)      |      | Continual Retrain  |
+--------------------+      +--------------------+
  1. Problem Formulation: Translate business objectives into a well-defined ML task (⟨T,P,E⟩\langle T, P, E \rangle). Determine whether supervised, unsupervised, or reinforcement learning is applicable.
  2. Data Acquisition & Labeling: Ingest historical records, web scraping logs, telemetry sensors, or third-party datasets.
  3. Exploratory Data Analysis (EDA) & Preprocessing: Clean corrupted entries, impute missing values, detect anomalies, normalize or standardize feature scales.
  4. Feature Engineering & Selection: Create domain-specific feature representations (e.g., polynomial features, datetime decomposition, text TF-IDF/embeddings).
  5. Model Selection & Training: Benchmark multiple hypothesis families (linear models, ensembles, deep networks) on training splits.
  6. Validation & Hyperparameter Optimization: Employ cross-validation and Bayesian search to tune regularization constants, learning rates, tree depths.
  7. Testing & Generalization Assessment: Evaluate the frozen final candidate model on a strictly held-out test split to estimate true real-world risk.
  8. Deployment & MLOps Monitoring: Package model into production inference endpoints (Docker, FastAPI, Triton); continuously track data drift, concept drift, latency, and predictive performance.