UNIT 3: MACHINE LEARNING ALGORITHMS AND ADVANCED TOPICS
I. FOUNDATIONS OF MACHINE LEARNING
Characteristics of a Good Algorithm:
-
Correctness: Produces the desired output for all valid inputs.
-
Efficiency: Optimal use of time (time complexity) and space (space complexity).
-
Finiteness: Terminates after a finite number of steps.
-
Input/Output: Clearly defined inputs and outputs.
-
Determinism/Non-determinism: Steps are precisely defined (deterministic) or may have choices (non-deterministic).
Tools for Algorithm Analysis:
-
Time Complexity: Measured using Big O notation to describe worst-case scenario growth rate.
- Example: $O(n)$, $$\displaystyle O(n^2) $$, $O(\log n)$.
-
Space Complexity: Memory required as a function of input size.
-
Asymptotic Analysis: Focuses on behavior for large input sizes.
Fundamental Techniques:
-
Divide and Conquer:
-
Steps: Divide problem → Conquer sub-problems recursively → Combine solutions.
-
Examples: Merge Sort, Quick Sort, Binary Search.
-
Complexity: Often $O(n \log n)$ for sorting.
-
[!TIP] Master Theorem used to solve recurrence: $$\displaystyle T(n) = aT(n/b) + f(n) $$.
-
-
Dynamic Programming:
-
Solves overlapping subproblems by storing results to avoid recomputation.
-
Steps: Characterize structure → Define value → Compute bottom-up → Construct solution.
-
Example: Fibonacci sequence with memoization ($O(n)$ vs naive $$\displaystyle O(2^n) $$).
-
[!TIP] Key: Optimal substructure + overlapping subproblems.
-
Well-Posed Learning Problem (according to Tom Mitchell):
A problem is well-posed if:
-
A task $T$ is defined (e.g., classification, regression).
-
A performance measure $P$ is specified (e.g., accuracy, MSE).
-
There exists experience $E$ from which the system can learn.
-
The performance $P$ improves with experience $E$.
II. DATA PREPARATION AND MODEL EVALUATION
Data Description and Preparation:
-
Description: Summarize data using statistics (mean, median, mode, variance) and visualization.
-
Preparation:
-
Cleaning: Handle missing values (imputation, deletion), outliers.
-
Transformation: Normalization (min-max), standardization (z-score).
-
Feature Engineering: Create new features, dimensionality reduction (PCA).
-
Holdout Method & Cross-Validation:
-
Holdout: Split data into training set and test set (e.g., 70%-30%). Simple but may have high variance.
-
k-Fold Cross-Validation:
-
Split data into $k$ equal folds.
-
Train on $k-1$ folds, validate on the remaining fold; repeat $k$ times.
-
Average performance across folds.
-
Common: $$\displaystyle k=10 $$.
-
[!TIP] Reduces bias compared to single holdout; computationally expensive.
-
Evaluation Metrics:
-
Confusion Matrix:
| | Predicted + | Predicted - | |---|---|---| | Actual + | TP | FN | | Actual - | FP | TN |
-
Precision = $$\displaystyle \frac{TP}{TP + FP} $$ → How many selected instances are relevant?
-
Recall (Sensitivity) = $$\displaystyle \frac{TP}{TP + FN} $$ → How many relevant instances are selected?
-
F1-Score = $$\displaystyle 2 \times \frac{\text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}} $$ → Harmonic mean.
-
Accuracy = $$\displaystyle \frac{TP + TN}{TP + TN + FP + FN} $$.
-
Specificity = $$\displaystyle \frac{TN}{TN + FP} $$.
-
[!TIP] Use Precision-Recall trade-off for imbalanced datasets; ROC-AUC for balanced.
Overfitting vs Underfitting:
| Overfitting | Underfitting |
|---|---|
| Model learns noise & details in training data. | Model is too simple; fails to capture underlying pattern. |
| High training accuracy, low test accuracy. | Low training & test accuracy. |
| High variance, low bias. | High bias, low variance. |
| Solutions: More data, regularization, pruning, dropout. | Solutions: More features, complex model, decrease regularization. |
Handling Noisy Data in Decision Trees:
-
Problem: Noise causes overfitting, creating overly complex trees.
-
Strategies:
-
Pre-pruning (Early stopping): Stop split if:
-
Sample count < threshold.
-
Information gain < threshold.
-
Tree depth exceeds limit.
-
-
Post-pruning: Build full tree, then remove branches that don't improve validation accuracy.
-
Reduced Error Pruning: Replace subtree with leaf if accuracy doesn't drop.
-
Cost-Complexity Pruning: Minimize $$\displaystyle R_\alpha(T) = R(T) + \alpha|T| $$ (error + penalty for leaves).
-
-
Ensemble Methods: Use Random Forest (averaging reduces noise impact).
-
Smoothing: Use Laplace correction for probability estimates.
-
III. SUPERVISED LEARNING ALGORITHMS
A. Linear Models
Least Squared Error Hypothesis:
-
Goal: Find linear function $$\displaystyle h_\theta(x) = \theta^T x $$ that minimizes Mean Squared Error (MSE).
-
Cost Function: $$\displaystyle J(\theta) = \frac{1}{2m} \sum_{i=1}^{m} (h_\theta(x^{(i)}) - y^{(i)})^2 $$.
-
Solution: Normal equation: $$\displaystyle \theta = (X^T X)^{-1} X^T y $$ (if $$\displaystyle X^T X $$ invertible).
-
Assumptions: Linear relationship, homoscedasticity, no multicollinearity, normal errors.
Gradient Descent (GD) for Linear Regression:
-
Update Rule: $$\displaystyle \theta_j := \theta_j - \alpha \frac{\partial}{\partial \theta_j} J(\theta) $$.
-
Gradient: $$\displaystyle \frac{\partial J(\theta)}{\partial \theta_j} = \frac{1}{m} \sum_{i=1}^{m} (h_\theta(x^{(i)}) - y^{(i)}) x_j^{(i)} $$.
-
Algorithm:
-
Initialize $\theta$ (often zeros).
-
Repeat until convergence:
-
Compute gradient vector.
-
Update all $$\displaystyle \theta_j $$ simultaneously.
-
-
Convergence: Cost decreases; check gradient magnitude.
-
GD Variants:
| Variant | Batch Size | Update Frequency | Pros | Cons |
|---|---|---|---|---|
| Batch GD | Entire dataset ($m$) | Per epoch | Stable convergence, exact gradient | Slow for large data, memory heavy |
| Stochastic GD (SGD) | 1 sample | Per sample | Fast updates, escapes local minima | Noisy convergence, may not converge |
| Mini-Batch GD | $b$ samples (e.g., 32, 64) | Per mini-batch | Balance of speed & stability | Need to tune batch size |
-
Learning Rate $\alpha$: Critical hyperparameter. Too large → divergence; too small → slow.
-
Convergence Criterion: $$\displaystyle |\nabla J(\theta)| < \epsilon $$ or max epochs.
Gradient Descent Delta Rule (for Neural Networks):
-
Applies GD to train single-layer perceptron (or neuron in MLP).
-
Error: $$\displaystyle \delta = (t - y) f'(net) $$, where $f'$ is derivative of activation function.
-
Weight Update: $$\displaystyle \Delta w_{ji} = \alpha \delta_j x_i $$.
-
For MLP, generalized via backpropagation (see Neural Networks section).
B. Decision Trees
Entropy & Information Gain:
-
Entropy (measure of impurity/uncertainty): $$\displaystyle H(S) = -\sum_{i=1}^{c} p_i \log_2 p_i $$, where $$\displaystyle p_i $$ = proportion of class $i$ in set $S$.
-
$$\displaystyle H(S)=0 $$: Pure (all same class).
-
$$\displaystyle H(S)=1 $$: Maximally impure (for binary balanced).
-
-
Information Gain (IG): Reduction in entropy after splitting on attribute $A$.
-
$$\displaystyle IG(S, A) = H(S) - \sum_{v \in \text{Values}(A)} \frac{|S_v|}{|S|} H(S_v) $$.
-
Choose attribute with highest IG at each node.
-
Example Calculation (from past paper):
| Sample | Credit Score | Loan Approved |
|---|---|---|
| 1 | High | Yes |
| 2 | Medium | No |
| 3 | Low | No |
| 4 | High | Yes |
| 5 | Medium | Yes |
| 6 | Low | No |
| 7 | High | No |
-
Overall Entropy $H(S)$:
-
Yes: 3/7, No: 4/7.
-
$$\displaystyle H(S) = -\left(\frac{3}{7}\log_2\frac{3}{7} + \frac{4}{7}\log_2\frac{4}{7}\right) \approx 0.985 $$.
-
-
IG for "Credit Score":
-
High (Samples 1,4,7): Yes=2, No=1 → $$\displaystyle H(\text{High}) = -\left(\frac{2}{3}\log_2\frac{2}{3} + \frac{1}{3}\log_2\frac{1}{3}\right) \approx 0.918 $$.
-
Medium (Samples 2,5): Yes=1, No=1 → $$\displaystyle H(\text{Med}) = 1.0 $$.
-
Low (Samples 3,6): Yes=0, No=2 → $$\displaystyle H(\text{Low}) = 0 $$.
-
$$\displaystyle IG = 0.985 - \left(\frac{3}{7} \times 0.918 + \frac{2}{7} \times 1.0 + \frac{2}{7} \times 0\right) \approx 0.985 - 0.655 = 0.330 $$.
-
-
\boxed{IG(\text{Credit Score}) \approx 0.330}
Recursive Induction (ID3/C4.5 Algorithm):
-
Base Cases:
-
All samples in node belong to same class → create leaf with that class.
-
No samples left → create leaf with majority class of parent.
-
No attributes left → create leaf with majority class.
-
-
Recursive Step:
-
Select best attribute $A$ (highest IG or Gini).
-
Create branch for each value $v$ of $A$.
-
For each branch, repeat on subset $$\displaystyle S_v $$ with remaining attributes.
-
-
Stopping: Use pre-pruning or post-pruning to avoid overfitting.
Lazy vs Eager Learning:
| Aspect | Lazy Learning (e.g., k-NN) | Eager Learning (e.g., Decision Trees) |
|---|---|---|
| Training | Just stores data; no explicit model built. | Builds general model during training. |
| Prediction | Computationally expensive (scans all data). | Fast (simple tree traversal). |
| Adaptability | Easily adapts to new data. | Requires retraining for new data. |
| Overfitting | Sensitive to irrelevant/noisy features. | Can overfit if tree deep; pruning helps. |
| Example | k-Nearest Neighbors, Case-Based Reasoning. | Decision Trees, Neural Networks, SVM. |
C. Probabilistic Models
Probabilistic Modeling:
-
Models uncertainty using probability distributions.
-
Example 1: Naïve Bayes Classifier:
-
Assumes feature independence: $$\displaystyle P(y|x_1,...,x_n) \propto P(y) \prod_{i} P(x_i|y) $$.
-
Predict $$\displaystyle \hat{y} = \arg\max_y P(y) \prod_i P(x_i|y) $$.
-
-
Example 2: Hidden Markov Models (HMM) for sequential data (e.g., speech recognition).
-
States $S$, Observations $O$, Transition $A$, Emission $B$, Initial $\pi$.
-
Tasks: Evaluation (Forward algorithm), Decoding (Viterbi), Learning (Baum-Welch).
-
Probabilistic Inference:
-
Compute posterior probabilities given evidence.
-
Exact Inference: Enumeration, Variable Elimination (complexity exponential in treewidth).
-
Approximate Inference:
-
Monte Carlo: Sampling (e.g., likelihood weighting).
-
Variational: Approximate distribution with simpler family (e.g., mean-field).
-
-
Application: Bayesian Networks, Markov Networks.
IV. ENSEMBLE METHODS
Bagging vs Boosting:
| Feature | Bagging (Bootstrap Aggregating) | Boosting |
|---|---|---|
| Goal | Reduce variance | Reduce bias |
| Sampling | Bootstrap samples (with replacement) | Weighted samples; misclassified get higher weight |
| Model Type | Parallel, independent learners (e.g., Decision Trees) | Sequential, dependent learners |
| Weighting | Equal weight for predictions (majority vote/average) | Weighted combination (e.g., $$\displaystyle \alpha_t h_t(x) $$) |
| Robustness | Handles high variance models well | Can overfit on noisy data |
| Examples | Random Forest | AdaBoost, Gradient Boosting, XGBoost |
Random Forest:
-
Architecture:
-
Ensemble of $N$ decision trees.
-
Each tree trained on bootstrap sample.
-
At each split, consider only random subset of features (feature bagging).
-
-
Working Mechanism:
-
For classification: Each tree votes; majority wins.
-
For regression: Average predictions.
-
Out-of-Bag (OOB) Error: Estimate using samples not in bootstrap (~37%); no need for separate validation.
-
-
Advantages:
-
Reduces overfitting (averaging).
-
Handles high-dimensional data.
-
Provides feature importance (mean decrease in impurity).
-
-
\boxed{\text{Prediction} = \text{mode}{h_1(x), ..., h_N(x)} \text{ (classification)}}
Ensemble Robustness:
-
Why Ensembles Outperform?
-
Statistical: Reduces variance (bagging) or bias (boosting).
-
Computational: Avoids local minima by combining multiple searches.
-
Representational: Expands hypothesis space (linear combination of models).
-
Diversity: Errors of individual models uncorrelated → average error decreases.
-
Noise Reduction: Averaging smooths out individual model's noise sensitivity.
-
-
[!TIP] Ensembles work best when base learners are accurate and diverse.
V. NEURAL NETWORKS
Multi-Layer Perceptron (MLP):
-
Architecture:
-
Input Layer: $n$ nodes (features).
-
Hidden Layers: 1+ layers with non-linear activation (ReLU, sigmoid, tanh).
-
Output Layer: $k$ nodes (e.g., softmax for classification, linear for regression).
-
Fully Connected: Each node in layer $l$ connected to all in layer $l+1$.
-
-
Activation Functions:
-
Sigmoid: $$\displaystyle \sigma(z) = \frac{1}{1+e^{-z}} $$; output (0,1); vanishing gradient.
-
ReLU: $\max(0,z)$; sparse activation; common in hidden layers.
-
Softmax: $$\displaystyle \frac{e^{z_i}}{\sum_j e^{z_j}} $$; for multi-class probability.
-
Learning Process:
-
Forward Propagation:
-
$$\displaystyle z^{(l)} = W^{(l)} a^{(l-1)} + b^{(l)} $$.
-
$$\displaystyle a^{(l)} = g(z^{(l)}) $$, where $g$ is activation.
-
-
Loss Function:
-
Classification: Cross-entropy $$\displaystyle L = -\sum y_i \log(\hat{y}_i) $$.
-
Regression: MSE $$\displaystyle L = \frac{1}{m}\sum (y - \hat{y})^2 $$.
-
-
Backpropagation:
-
Compute gradient $$\displaystyle \frac{\partial L}{\partial W^{(l)}} $$ via chain rule.
-
Output layer error: $$\displaystyle \delta^{(L)} = \nabla_a L \odot g'(z^{(L)}) $$.
-
Hidden layer error: $$\displaystyle \delta^{(l)} = (W^{(l+1)})^T \delta^{(l+1)} \odot g'(z^{(l)}) $$.
-
Gradients: $$\displaystyle \frac{\partial L}{\partial W^{(l)}} = \delta^{(l)} (a^{(l-1)})^T $$.
-
-
Gradient Descent Update:
-
$$\displaystyle W^{(l)} := W^{(l)} - \alpha \frac{\partial L}{\partial W^{(l)}} $$.
-
Repeat for all layers (from $L$ to 1).
-
-
[!TIP] Backpropagation efficiently computes gradients by reusing intermediate results.
VI. REINFORCEMENT LEARNING
A. Fundamentals
Markov Decision Process (MDP):
-
Defined by tuple $(S, A, P, R, \gamma)$:
-
$S$: Set of states.
-
$A$: Set of actions.
-
$P(s'|s,a)$: Transition probability to $s'$ from $s$ taking $a$.
-
$R(s,a,s')$: Reward function.
-
$\gamma \in [0,1]$: Discount factor.
-
-
Markov Property: Future state depends only on current state/action, not history.
-
Policy $\pi(a|s)$: Probability of taking action $a$ in state $s$.
-
Goal: Find optimal policy $$\displaystyle \pi^* $$ maximizing expected cumulative discounted reward: $$\displaystyle G_t = R_{t+1} + \gamma R_{t+2} + ... $$.
Bellman Equations:
-
State Value Function $$\displaystyle V^\pi(s) $$: Expected return starting from $s$ following $\pi$.
- $$\displaystyle V^\pi(s) = \sum_a \pi(a|s) \sum_{s',r} P(s',r|s,a)[r + \gamma V^\pi(s')] $$.
-
Action Value Function $$\displaystyle Q^\pi(s,a) $$: Expected return taking $a$ in $s$ then $\pi$.
- $$\displaystyle Q^\pi(s,a) = \sum_{s',r} P(s',r|s,a)[r + \gamma \sum_{a'} \pi(a'|s') Q^\pi(s',a')] $$.
-
Optimality:
-
$$\displaystyle V^*(s) = \max_a \sum_{s',r} P(s',r|s,a)[r + \gamma V^*(s')] $$.
-
$$\displaystyle Q^*(s,a) = \sum_{s',r} P(s',r|s,a)[r + \gamma \max_{a'} Q^*(s',a')] $$.
-
-
\boxed{V^(s) = \max_a Q^(s,a)} \quad \boxed{Q^(s,a) = \mathbb{E}[r + \gamma V^(s')]}
B. Value-Based Methods
Value Iteration:
-
Initialize $$\displaystyle V_0(s) $$ arbitrarily.
-
Repeat until convergence:
- $$\displaystyle V_{k+1}(s) \leftarrow \max_a \sum_{s',r} P(s',r|s,a)[r + \gamma V_k(s')] $$.
-
Policy Extraction: $$\displaystyle \pi(s) = \arg\max_a \sum_{s',r} P(s',r|s,a)[r + \gamma V^*(s')] $$.
-
Guarantee: Converges to $$\displaystyle V^* $$; each iteration improves value.
Policy Iteration:
-
Policy Evaluation: Compute $$\displaystyle V^\pi $$ for current $\pi$ (solve linear system or iterative).
-
Policy Improvement: Update $\pi$ greedily: $$\displaystyle \pi'(s) = \arg\max_a Q^\pi(s,a) $$.
-
Repeat until $\pi$ stable (no change).
- Faster convergence than value iteration but each iteration costlier.
Q-learning vs SARSA:
| Aspect | Q-learning | SARSA |
|---|---|---|
| Type | Off-policy | On-policy |
| Update Rule | $$\displaystyle Q(s,a) \leftarrow Q(s,a) + \alpha [r + \gamma \max_{a'} Q(s',a') - Q(s,a)] $$ | $$\displaystyle Q(s,a) \leftarrow Q(s,a) + \alpha [r + \gamma Q(s',a') - Q(s,a)] $$ |
| Policy | Learns optimal $$\displaystyle Q^* $$ independent of behavior policy. | Learns $$\displaystyle Q^\pi $$ for current $\pi$ (e.g., $\epsilon$-greedy). |
| Convergence | To optimal policy with exploration. | To policy of behavior (may be suboptimal). |
| Risk | Can overestimate values; may be unstable. | More conservative; follows current policy. |
Temporal Difference (TD) Learning vs Monte Carlo (MC):
| Feature | TD Learning | Monte Carlo |
|---|---|---|
| Update | After each step: $$\displaystyle V(s_t) \leftarrow V(s_t) + \alpha [r_{t+1} + \gamma V(s_{t+1}) - V(s_t)] $$ | After episode end: $$\displaystyle V(s_t) \leftarrow V(s_t) + \alpha [G_t - V(s_t)] $$ |
| Bootstrap | Yes (uses current estimate). | No (uses actual return). |
| Variance | Lower (bootstrapping reduces variance). | Higher (depends on full trajectory). |
| Convergence | To $$\displaystyle V^\pi $$ (if learning rate decays appropriately). | To $$\displaystyle V^\pi $$ (with sufficient exploration). |
| Terminal States | Can learn without episode completion. | Requires complete episodes. |
| Example | SARSA, Q-learning. | Every-Visit MC, First-Visit MC. |
C. Policy Gradient Methods
-
Directly optimize policy $$\displaystyle \pi_\theta(a|s) $$ parameterized by $\theta$.
-
Objective: Maximize expected return $$\displaystyle J(\theta) = \mathbb{E}_{\pi_\theta} [G_t] $$.
-
REINFORCE Algorithm (Monte Carlo policy gradient):
-
Generate trajectory $$\displaystyle (s_t, a_t, r_t) $$ using $$\displaystyle \pi_\theta $$.
-
For each step: $$\displaystyle \theta \leftarrow \theta + \alpha G_t \nabla \log \pi_\theta(a_t|s_t) $$.
-
-
Advantage: Can learn stochastic policies; suitable for continuous actions.
-
Challenge: High variance → use baselines (e.g., $$\displaystyle b = V(s) $$) → $$\displaystyle G_t - V(s) $$ as advantage estimate.
-
Actor-Critic: Combine policy gradient (actor) with value function (critic) for lower variance.
D. Advanced Topics
Generative Adversarial Imitation Learning (GAIL):
-
Goal: Learn policy from expert demonstrations (no reward).
-
Architecture:
-
Generator (Policy): Produces trajectories.
-
Discriminator: Distinguishes expert vs generated trajectories.
-
-
Training: Adversarial: Policy tries to fool discriminator; discriminator tries to classify correctly.
-
Difference from Standard RL:
-
Standard RL: Learn from reward signal.
-
GAIL: Learn from demonstrations; reward is implicit from discriminator.
-
GAIL avoids reward engineering; more sample-efficient than behavioral cloning.
-
Recent Trends in RL Architectures:
-
Deep RL: Combine deep neural networks with RL (DQN, DDPG, PPO).
-
Model-Based RL: Learn environment model for planning (e.g., Dreamer, MuZero).
-
Hierarchical RL: Decompose tasks into sub-policies (options, feudal networks).
-
Multi-Agent RL: Multiple agents interacting (cooperative/competitive).
-
Meta-RL: Learn to adapt quickly to new tasks (e.g., MAML).
-
Offline RL: Learn from fixed dataset without environment interaction (e.g., BCQ, CQL).
-
RL for Real-World: Applications in robotics, healthcare, finance with safety constraints.
VII. ADVANCED TOPICS AND APPLICATIONS
Game Theory in AI:
-
Minimax Algorithm (for two-player zero-sum games):
-
Idea: Assume opponent plays optimally; minimize maximum loss.
-
Procedure:
-
Build game tree (states, actions, terminal utilities).
-
Assign utilities to terminal nodes.
-
Back up: At MAX node → $\max$ of children; at MIN node → $\min$ of children.
-
Choose move leading to highest minimax value.
-
-
Functions:
-
minimax(state, depth, maximizingPlayer):-
If terminal or depth=0: return utility.
-
If maximizing: $$\displaystyle v = -\infty $$; for each action: $$\displaystyle v = \max(v, \text{minimax}(child, depth-1, \text{false})) $$; return $v$.
-
If minimizing: $$\displaystyle v = +\infty $$; for each action: $$\displaystyle v = \min(v, \text{minimax}(child, depth-1, \text{true})) $$; return $v$.
-
-
-
Alpha-Beta Pruning: Skip branches that won't affect decision.
-
Maintain $\alpha$ (best for max so far), $\beta$ (best for min so far).
-
Prune when $\alpha \geq \beta$.
-
-
-
Equilibrium Concepts:
-
Nash Equilibrium: No player can improve payoff by unilaterally changing strategy.
-
Pure Strategy: Deterministic choice.
-
Mixed Strategy: Probability distribution over actions.
-
-
Pay-off Matrix Analysis:
-
Saddle Point: $$\displaystyle \max_i \min_j a_{ij} = \min_j \max_i a_{ij} $$.
-
Dominance: Row $i$ dominates $k$ if $$\displaystyle a_{ij} \geq a_{kj} $$ for all $j$ (strict > for some).
-
Solution of 2x2 Games: Use dominance reduction or mixed strategy formulas.
-
Example (from past paper):
| A\B | I | II | III | |---|---|---|---| | I | 5 | 9 | 3 | | II | 6 | 14 | 4 |
-
Dominance: Row II > Row I? Compare: 6>5, 14>9, 4>3 → Yes, II dominates I. So reduce to Row II.
-
Column comparison: III vs I/II? Not clear. Compute values:
-
If B plays I: A gets 6.
-
If B plays II: A gets 14.
-
If B plays III: A gets 4.
-
-
A will choose II (maximin = 6? Actually maximin: min over columns for each row → Row I: min(5,9,3)=3; Row II: min(6,14,4)=4 → maximin=4). But with dominance, A chooses II.
-
B wants minimize A's payoff: For Row II, B chooses III (min 4) or I (6)? B chooses min → III gives 4.
-
Saddle Point? Check: $$\displaystyle \max_i \min_j a_{ij} = \max(3,4)=4 $$; $$\displaystyle \min_j \max_i a_{ij} = \min(\max(5,6)=6, \max(9,14)=14, \max(3,4)=4) = 4 $$. Equal → saddle point at (II, III) with value 4.
-
-
Search Algorithms for Pathfinding:
-
Breadth-First Search (BFS):
-
Mechanism: Explore all neighbors at current depth before next depth.
-
Data Structure: Queue (FIFO).
-
Properties: Complete (finds solution if exists), optimal for unweighted graphs, time $$\displaystyle O(b^d) $$, space $$\displaystyle O(b^d) $$ ($b$=branching, $d$=depth).
-
Pseudocode:
frontier = Queue([start]) explored = set() while frontier: node = frontier.pop() if node == goal: return path explored.add(node) for child in node.expand(): if child not in explored and not in frontier: frontier.push(child)
-
-
A Algorithm*:
-
Evaluation Function: $$\displaystyle f(n) = g(n) + h(n) $$.
-
$g(n)$: cost from start to $n$.
-
$h(n)$: admissible heuristic (never overestimates true cost to goal).
-
-
Properties: Complete, optimal if $h$ admissible & consistent (monotone).
-
Data Structure: Priority queue ordered by $f(n)$.
-
Time/Space: $$\displaystyle O(b^d) $$ worst-case, but much better with good heuristic.
-
[!TIP] Heuristic design critical: $$\displaystyle h(n)=0 $$ → BFS; $h(n)$ exact → best-first.
-
Rule-Based Systems and State Machines:
-
Finite State Machine (FSM):
-
States, transitions (triggered by events/inputs), actions.
-
Example (from past paper: guard/thief scenario):
-
States:
Guard,Fight,Flee,StandGuard. -
Transitions:
-
StandGuard→Fighton "see thief & not strong". -
StandGuard→Fleeon "see thief & strong". -
Fight→Fleeon "losing". -
Flee→Guardon "escape".
-
-
Represented as state diagram or transition table.
-
-
Pros: Simple, predictable. Cons: Not scalable for complex behaviors.
-
-
Behavior Trees:
-
Hierarchical nodes: Control (Sequence, Selector, Parallel) and Execution (Action, Condition).
-
Sequence: Execute children in order; fail if any child fails.
-
Selector: Execute children until one succeeds.
-
Advantage over FSM: More modular, reusable, easier to design complex AI behaviors (common in games).
-
Time Series Forecasting:
-
Fuzzy Time Series:
-
Use fuzzy logic to handle uncertainty in time series.
-
Steps:
-
Partition universe of discourse into intervals (fuzzy sets).
-
Fuzzify observations (membership degrees).
-
Establish fuzzy logical relationships (e.g., $$\displaystyle A_t \rightarrow B_{t+1} $$).
-
Forecast by defuzzification (e.g., centroid).
-
-
Advantage: Handles linguistic variables, non-stationary data.
-
-
Markov Chain Models:
-
States represent discrete levels (e.g., "low", "medium", "high" demand).
-
Transition matrix $P$ where $$\displaystyle P_{ij} = P(S_{t+1}=j | S_t=i) $$.
-
Forecast: $$\displaystyle S_{t+1} $$ distribution = $$\displaystyle S_t \times P $$.
-
Steady-state: Solve $$\displaystyle \pi = \pi P $$.
-
Application: Weather prediction, stock trends (simplified).
-
Data Product Strategy and Types:
-
Steps for Building Strategy:
-
Define Business Problem: Align with KPIs.
-
Data Collection & Infrastructure: Ensure quality, scalability.
-
Model Development: Choose appropriate ML algorithm; iterate.
-
Deployment: API, batch processing, real-time.
-
Monitoring & Maintenance: Track performance, drift, retrain.
-
Feedback Loop: Incorporate user feedback.
-
-
Types of Data Products by Functionality:
| Type | Function | Example | |---|---|---| | Descriptive | Summarize past/present data. | Dashboards, reports. | | Predictive | Forecast future outcomes. | Churn prediction, demand forecasting. | | Prescriptive | Recommend actions. | Recommendation systems, dynamic pricing. | | Automated | Execute decisions autonomously. | Fraud detection blocking transactions. |
VIII. DATA SCIENCE IMPLEMENTATION (PYTHON)
Data Handling:
-
CSV:
pandas.read_csv('file.csv'). -
JSON:
pandas.read_json('file.json')orjson.load(open('file.json')). -
Data Extraction:
-
Web Scraping:
BeautifulSoupfor HTML parsing.from bs4 import BeautifulSoup import requests response = requests.get(url) soup = BeautifulSoup(response.content, 'html.parser') data = soup.find_all('tag', class_='...') -
API:
requests.get(url).json().
-
-
String to JSON Array:
import json string_data = '[{"name":"Alice","age":30},{"name":"Bob","age":25}]' json_array = json.loads(string_data) # Returns list of dicts
Text Processing Libraries:
-
NLTK: Tokenization, stemming, lemmatization, stopwords.
-
spaCy: Industrial-strength NLP; pre-trained models, entity recognition.
-
TextBlob: Simple API for common tasks (sentiment, translation).
-
scikit-learn:
CountVectorizer,TfidfVectorizerfor feature extraction.
Numerical Computing with NumPy:
-
Statistical Calculations:
import numpy as np data = np.array([1,2,3,4,5]) avg = np.mean(data) # 3.0 var = np.var(data) # 2.0 (population by default) std = np.std(data) # 1.414... -
Matrix Operations:
-
np.dot(A, B)orA @ Bfor multiplication. -
np.linalg.inv(A)for inverse. -
np.linalg.eig(A)for eigenvalues/vectors.
-
Data Visualization with Matplotlib:
-
Bar Chart (from past paper example):
import matplotlib.pyplot as plt subjects = ['English', 'Hindi', 'Maths', 'Science', 'GK'] marks = [69, 90, 76, 88, 91] plt.bar(subjects, marks, color='skyblue') plt.xlabel('Subject') plt.ylabel('Marks') plt.title('Student Marks') plt.show()
Machine Learning with TensorFlow:
-
Implementing Gradient Descent:
import tensorflow as tf # Model: y = W*x + b W = tf.Variable(tf.random.normal([1])) b = tf.Variable(tf.random.normal([1])) learning_rate = 0.01 optimizer = tf.optimizers.SGD(learning_rate) for epoch in range(epochs): with tf.GradientTape() as tape: y_pred = W * x_train + b loss = tf.reduce_mean(tf.square(y_pred - y_train)) gradients = tape.gradient(loss, [W, b]) optimizer.apply_gradients(zip(gradients, [W, b])) -
Mini-Batch Gradient Descent:
-
Use
tf.data.Datasetto create batches:dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train)).batch(batch_size) for x_batch, y_batch in dataset: # Training step on batch -
Advantage: Faster convergence than batch GD; less noisy than SGD.
-
[!TIP] Always scale features for gradient descent (use
StandardScalerfrom scikit-learn) to ensure stable convergence.