Skip to content
AL-702 (C) · Predictive Analytics/Quick Revision Short Notes

Predictive Analytics (AL-702 (C)) - Unit 1 Short Notes

Unit 1: Predictive Analytics – Comprehensive Short Notes


1. Introduction to Predictive Analytics

Data Product Strategy is a structured plan to create, deploy, and maintain data-driven applications that deliver measurable value. The steps for building a successful strategy are:

  1. Identify Business Problem & Define Success Metric: Clearly articulate the predictive goal (e.g., "reduce customer churn by 10%") and define Key Performance Indicators (KPIs).

  2. Data Asset Assessment: Inventory available internal/external data sources. Evaluate quality (completeness, accuracy), volume, and accessibility.

  3. Feasibility & Approach Selection: Determine if the problem is solvable with available data and tools. Choose between statistical modeling, machine learning, or rule-based systems.

  4. Prototype & Validate: Build a Minimum Viable Product (MVP) or proof-of-concept. Use historical data for backtesting and validate model performance against the success metric.

  5. Deployment & Integration: Integrate the model into business workflows (e.g., API, dashboard, automated decision system). Ensure scalability and reliability.

  6. Monitoring & Maintenance: Continuously track model drift (performance degradation) and data drift (changing data distributions). Establish a retraining schedule.

Types of Data Products by Functionality:

Functionality Type Description Example
Descriptive Summarizes historical data to understand past events. Sales dashboard, customer segmentation report.
Diagnostic Explains why something happened by analyzing root causes. Churn analysis report identifying key dissatisfaction drivers.
Predictive Forecasts future outcomes based on patterns in historical data. Credit scoring model, demand forecasting system.
Prescriptive Recommends specific actions to achieve a desired outcome. Dynamic pricing engine, personalized treatment recommendation system.

[!TIP] Exam Focus: Be prepared to map a real-world business scenario (e.g., fraud detection, recommendation system) to these strategy steps and product types.


2. Data Management with Python

Data Extraction involves collecting raw data from various sources. Key Python tools/techniques:

  • Files: pandas.read_csv(), pandas.read_json(), open() for text files.

  • Databases: SQLAlchemy (for SQL), pymongo (for MongoDB).

  • Web APIs: requests library (GET/POST calls).

  • Web Scraping: BeautifulSoup (HTML/XML parsing), Scrapy (framework), Selenium (dynamic JavaScript pages).

CSV & JSON Handling:


# CSV

import pandas as pd

df = pd.read_csv('data.csv')  # Read

df.to_csv('output.csv', index=False)  # Write

# JSON

import json

# Read from file

with open('data.json', 'r') as f:

    data = json.load(f)

# Write to file

with open('output.json', 'w') as f:

    json.dump(data, f, indent=4)

Text Processing Libraries:

  • NLTK: Comprehensive toolkit for tokenization, stemming, lemmatization, stop-word removal, POS tagging.

  • spaCy: Industrial-strength, optimized for performance. Provides pre-trained models for NER, dependency parsing.

Numerical Computing with NumPy:

  • Core object: ndarray (N-dimensional array).

  • Key operations: Element-wise math, matrix multiplication (@ or np.dot()), broadcasting, slicing.

  • Matrix Inversion: np.linalg.inv(A) computes the inverse of square matrix A. Solves Ax = b via np.linalg.solve(A, b).

Data Visualization with Matplotlib:

  • Purpose: Create static, interactive, and animated visualizations in Python.

  • Applications: Exploratory data analysis (EDA), presenting model results, creating publication-quality figures.

  • Bar Chart 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 Performance')

plt.show()

Web Scraping with BeautifulSoup:


from bs4 import BeautifulSoup

import requests

url = 'https://example.com'

response = requests.get(url)

soup = BeautifulSoup(response.content, 'html.parser')

# Extract all paragraph texts

paragraphs = [p.get_text() for p in soup.find_all('p')]

[!TIP] Common Pitfall: Always check response.status_code after a requests.get(). Handle potential None returns from soup.find().


3. Statistical Foundations and Data Preparation

Descriptive Statistics (NumPy):

  • Average (Mean): np.mean(data)

  • Variance: np.var(data) (population by default, use ddof=1 for sample variance).

  • Standard Deviation: np.std(data) (square root of variance).

Data Description & Preparation for ML:

  • Goal: Transform raw data into a clean, structured format suitable for model training.

  • Steps: Handle missing values, encode categorical variables (Label/One-Hot Encoding), feature scaling (Normalization/Standardization), feature engineering.

Handling Missing Data:

  • Deletion: Remove rows/columns with missing values (only if very few missing).

  • Imputation: Fill with mean/median/mode (for numerical), most frequent category (for categorical), or use predictive models (e.g., KNN imputer).

  • Indicator: Add a binary column indicating if the value was missing.

Handling Outliers:

  • Detection: IQR method (values beyond Q1 - 1.5*IQR or Q3 + 1.5*IQR), Z-score (|Z| > 3).

  • Mitigation: Capping (winsorization), transformation (log), or removal if erroneous.


4. Machine Learning Fundamentals

Algorithm Characteristics: Finiteness, Definiteness, Input, Output, Effectiveness.

Tools to Analyze Algorithms:

  • Time Complexity: Big O notation (e.g., O(n), O(n²)).

  • Space Complexity: Memory usage.

  • Correctness: Does it solve the problem for all valid inputs?

  • Optimality: Does it produce the best possible solution?

Well-Posed Learning Problem (Definition): A problem is well-posed for learning if:

  1. There exists a pattern (target function f) to be learned.

  2. There is a large set of examples (training data) of this pattern.

  3. There is a performance measure (e.g., accuracy) defined on unseen examples.

  • Example: Predicting house prices. Pattern = price as a function of features (size, location). Examples = historical sales data. Performance = RMSE on new listings.

Probabilistic Modeling & Inference:

  • Need: To handle uncertainty in data and predictions. Models probability distributions, not deterministic functions.

  • Usage: Naïve Bayes classifier, Hidden Markov Models, Bayesian networks.

  • Example: In spam detection, compute P(Spam | Words) using Bayes' theorem.

Dynamic Programming (DP) in ML:

  • Importance: Solves complex problems by breaking them into overlapping subproblems, storing results to avoid recomputation.

  • Example: Sequence Alignment (bioinformatics), Viterbi Algorithm (for HMMs), Value Iteration in Reinforcement Learning.

Divide and Conquer Technique:

  • Concept: Break a problem into smaller, independent subproblems, solve them recursively, and combine solutions.

  • Example: Decision Tree Induction (split dataset on feature, build subtrees), Merge Sort.

Least Squared Error Hypothesis:

The hypothesis h(x) that minimizes the sum of squared differences between predicted and actual values.

\[ J(\theta) = \frac{1}{2m} \sum_{i=1}^{m} (h_\theta(x^{(i)}) - y^{(i)})^2 \]

Goal: Find parameters θ that minimize J(θ).

Lazy vs Eager Learning:

Feature Lazy Learning (e.g., k-NN) Eager Learning (e.g., Decision Trees, Neural Nets)
Training Simply stores training data. No explicit model building. Constructs a general model during training phase.
Prediction Computationally expensive (scans all data). Fast (uses pre-built model).
Adaptability Adapts quickly to new data. Requires retraining for data changes.
Example k-Nearest Neighbors Linear Regression, SVM, MLP

Holdout Method & Cross-Validation:

  • Holdout: Split data into Train and Test sets (e.g., 70/30). Train on train set, evaluate on test set. Simple but sensitive to split.

  • k-Fold Cross-Validation:

    1. Partition data into k equal folds.

    2. For each fold i: Train on all folds except i, validate on fold i.

    3. Average performance across k runs. More robust estimate of model performance.


5. Supervised Learning Algorithms

5.1 Linear Regression

  • Simple: y = β₀ + β₁x

  • Multiple: y = β₀ + β₁x₁ + β₂x₂ + ... + βₙxₙ

  • Cost Function (MSE):

    \[ MSE = \frac{1}{m} \sum_{i=1}^{m} (y^{(i)} - \hat{y}^{(i)})^2 \]

  • Gradient Descent (GD): Iteratively update parameters to minimize cost.

    \[ \theta_j := \theta_j - \alpha \frac{\partial}{\partial \theta_j} J(\theta) \]

    • Batch GD: Uses all training examples per update. Stable but slow for large data.

    • Mini-batch GD: Uses a small random subset (batch) per update. Most common in practice (balance of speed/stability).

  • Implementation in Python (from scratch):


def gradient_descent(X, y, theta, alpha, iterations):

    m = len(y)

    for _ in range(iterations):

        prediction = X.dot(theta)

        error = prediction - y

        gradient = (1/m) * X.T.dot(error)

        theta -= alpha * gradient

    return theta

  • Gradient Descent in TensorFlow:

    1. Define variables (tf.Variable) and placeholders (tf.placeholder).

    2. Construct the model graph (e.g., y_pred = tf.matmul(X, W) + b).

    3. Define loss function (tf.reduce_mean(tf.square(y_pred - y))).

    4. Choose optimizer (tf.train.GradientDescentOptimizer(learning_rate)) and minimize loss.

    5. Initialize variables and run session to execute training loop.

5.2 Decision Trees

  • Entropy (Measure of Impurity):

    \[ H(S) = -\sum_{i=1}^{c} p_i \log_2 p_i \]

    where p_i is proportion of class i in set S.

  • Information Gain (IG): Reduction in entropy after splitting on attribute A.

    \[ IG(S, A) = H(S) - \sum_{v \in Values(A)} \frac{|S_v|}{|S|} H(S_v) \]

  • Recursive Induction (ID3/C4.5):

    1. Start with all training data at root.

    2. Select the attribute with highest Information Gain.

    3. Create a branch for each value of that attribute.

    4. Recurse on each branch with remaining data/attributes (until stopping condition: all examples same class, no attributes left, or minimum samples).

  • Impact of Noisy Data & Mitigation:

    • Impact: Overfitting (tree becomes overly complex, captures noise).

    • Strategies:

      • Pruning: Remove branches that provide little predictive power (pre-pruning: stop early; post-pruning: grow full tree then trim).

      • Minimum Samples per Leaf/Node: Prevent splits with very few samples.

      • Ensemble Methods: Use Random Forest (see Unit 6) which averages many trees to reduce variance.

Example: Entropy & Information Gain Calculation

Dataset from Dec 2025 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
  1. Total Entropy H(S):

    • Yes: 3/7, No: 4/7.

    \[ H(S) = -\left(\frac{3}{7}\log_2\frac{3}{7} + \frac{4}{7}\log_2\frac{4}{7}\right) \approx 0.985 \]

  2. IG for "Credit Score":

    • High (3 samples): Yes=2, No=1 → H(High) ≈ 0.918

    • Medium (2 samples): Yes=1, No=1 → H(Medium) = 1.0

    • Low (2 samples): Yes=0, No=2 → H(Low) = 0.0

    \[ IG(S, \text{Credit}) = 0.985 - \left(\frac{3}{7}*0.918 + \frac{2}{7}*1.0 + \frac{2}{7}*0.0\right) \approx 0.985 - 0.689 = 0.296 \]

    (Repeat for other attributes; highest IG chosen for root).

5.3 Neural Networks (Multi-Layer Perceptron - MLP)

  • Architecture:

    • Input Layer: One neuron per feature.

    • Hidden Layer(s): Apply non-linear activation functions (ReLU, Sigmoid, Tanh).

    • Output Layer: Activation depends on task (Sigmoid for binary classification, Softmax for multi-class, Linear for regression).

    • Fully Connected: Each neuron in layer l connected to all neurons in layer l+1.

  • Learning Process:

    1. Forward Propagation: Compute output layer prediction \hat{y} from input X through successive layer transformations: z = Wx + b, a = g(z).

    2. Compute Loss: Compare \hat{y} to true y using loss function (e.g., Cross-Entropy, MSE).

    3. Backpropagation: Apply Chain Rule to compute gradient of loss w.r.t. each weight/bias. Propagates error backward from output to input.

    4. Weight Update: Use Gradient Descent (or variant like Adam) to update parameters: W := W - α * ∂Loss/∂W.

  • Gradient Descent Delta Rule (Single-Layer Perceptron): Weight update for neuron j:

    \[ \Delta w_{ji} = \eta (t_j - y_j) x_i \]

    where η is learning rate, t_j target, y_j output, x_i input. Only works for linearly separable problems.

5.4 Least Squares Methods

  • Ordinary Least Squares (OLS): Analytical solution for linear regression. Finds θ that minimizes residual sum of squares (RSS).

    \[ \theta = (X^T X)^{-1} X^T y \]

    Assumptions: Linear relationship, no multicollinearity, homoscedasticity, uncorrelated errors, normally distributed errors (for inference).

  • Application in Regression: Provides Best Linear Unbiased Estimator (BLUE) under Gauss-Markov assumptions. Used for parameter estimation and inference (p-values, confidence intervals).


6. Ensemble Learning

Aspect Bagging (Bootstrap Aggregating) Boosting
Core Idea Build many independent models on bootstrapped samples, average/vote. Build models sequentially, each new model focuses on errors of previous ones.
Example Random Forest AdaBoost, Gradient Boosting (XGBoost, LightGBM)
Goal Reduce variance (overfitting). Reduce bias (underfitting).
Sampling Bootstrap (random sample with replacement). Weighted sampling; misclassified points get higher weight.
Model Weight All models have equal weight in final prediction. Models are weighted by their accuracy (better models have more say).
Parallelization Possible (models independent). Not possible (sequential).

Random Forest Algorithm:

  1. For b = 1 to B (number of trees):

    • Draw a bootstrap sample from training data.

    • Grow a decision tree on this sample. At each split, randomly select a subset of features (e.g., √p) and find the best split only among those features.

  2. Final prediction: Average (regression) or majority vote (classification) of all B trees.

Why Ensembles are More Robust:

  • Variance Reduction (Bagging): Averaging multiple high-variance models (like deep trees) smooths out their individual fluctuations, leading to more stable predictions.

  • Bias Reduction (Boosting): Sequentially correcting errors forces the ensemble to learn complex patterns a single weak learner cannot.

  • Error Decomposition: Ensemble error = Average model error + Diversity term. Ensembles exploit diversity among base models; errors tend to cancel out. A single model's error is not compensated.


7. Reinforcement Learning

Markov Decision Process (MDP): Formal framework for RL. Defined by tuple (S, A, P, R, γ):

  • S: Set of states.

  • A: Set of actions.

  • P(s'|s,a): Transition probability to state s' from s taking action a.

  • R(s,a,s'): Reward received.

  • γ: Discount factor (0 ≤ γ ≤ 1).

Bellman Equations (Context): Define optimal value functions recursively.

  • State-Value: V*(s) = max_a Σ_{s'} P(s'|s,a)[R(s,a,s') + γ V*(s')]

  • Action-Value: Q*(s,a) = Σ_{s'} P(s'|s,a)[R(s,a,s') + γ max_{a'} Q*(s',a')]

  • Significance: They are the fixed-point equations that define optimality. Algorithms like Value Iteration and Q-learning are derived from them.

Value Iteration vs Policy Iteration (Short Note):

Value Iteration Policy Iteration
Steps 1. Initialize V(s) arbitrarily. <br> 2. Repeat: `V(s) ← max_a Σ_{s'} P(s' s,a)[R + γ V(s')]` until convergence. <br> 3. Extract greedy policy.
Pros/Cons Simpler update, often faster per iteration. May converge slowly. Often fewer iterations to converge, but each iteration is expensive (policy evaluation).

Temporal Difference (TD) Learning vs Monte Carlo (MC):

Temporal Difference (TD) Monte Carlo (MC)
Update Target R_{t+1} + γ V(S_{t+1}) (bootstraps from current estimate). Full return G_t = R_{t+1} + γ R_{t+2} + ... + γ^{T-t} R_T (waits for episode end).
Learning Online/Incremental. Updates after each step. Episode-based. Updates only at episode termination.
Convergence Converges to V_π under certain conditions. Converges to V_π (or V_* with exploring starts).
Variance Lower variance (uses current estimate). Higher variance (depends on full trajectory randomness).
Example SARSA, Q-learning, TD(0) Every-Visit MC, First-Visit MC

Q-learning (Off-policy) vs SARSA (On-policy):

  • Q-learning: Learns optimal policy π* independent of the agent's current behavior policy (e.g., ε-greedy). Updates using max_a' Q(S', a').

    \[ Q(S,A) \leftarrow Q(S,A) + \alpha [R + \gamma \max_{a'} Q(S', a') - Q(S,A)] \]

  • SARSA: Learns the current behavior policy (on-policy). Updates using the actual next action A' taken.

    \[ Q(S,A) \leftarrow Q(S,A) + \alpha [R + \gamma Q(S', A') - Q(S,A)] \]

  • Key Difference: Q-learning is "greedy" in the update (optimistically assumes best action), SARSA is "realistic" (uses actual action). Q-learning can be less stable but converges to optimal policy if exploration is sufficient.

Policy Gradient Methods (Concept):

  • Directly learn/optimize the policy function π_θ(a|s) (parameterized by θ), without learning a value function.

  • Goal: Maximize expected return J(θ) = E_π[R].

  • REINFORCE Algorithm (Example):

    1. Generate an episode using current policy π_θ.

    2. For each step t in episode, compute return G_t.

    3. Update policy parameters: θ ← θ + α γ^t G_t ∇_θ log π_θ(A_t|S_t).

  • Advantage: Can learn stochastic policies, suitable for continuous action spaces.

Generative Adversarial Imitation Learning (GAIL) vs Standard RL:

  • Standard RL: Agent learns by interacting with environment, receiving scalar rewards. Requires designing a reward function.

  • GAIL: Imitation Learning approach. Agent learns by mimicking expert demonstrations (e.g., human driving data).

    • Uses two networks: Generator (Policy) and Discriminator.

    • Discriminator tries to distinguish state-action pairs from expert vs agent.

    • Generator (policy) tries to fool discriminator.

    • Objective: Match the expert's state-action distribution, not maximize a hand-crafted reward.

    • Advantage: Avoids reward function design; learns from raw demonstrations.

Recent Trends in RL Architectures:

  • Deep RL: Combining deep neural networks with RL (DQN, PPO, SAC).

  • Model-Based RL: Learning a model of environment dynamics to plan (e.g., Dreamer, MuZero).

  • Multi-Agent RL (MARL): Training multiple interacting agents (cooperative/competitive).

  • Hierarchical RL: Learning temporally extended actions (options) for long-horizon tasks.

  • Meta-RL: "Learning to learn" – adapting quickly to new tasks.


8. Game Theory and AI for Games

8.1 Game Theory Basics

  • Definition: Study of mathematical models of strategic interaction among rational decision-makers.

  • Application to AI: Provides formal framework for designing agents that compete/cooperate optimally in multi-agent environments (e.g., poker, auctions, autonomous driving).

  • Payoff Matrix: Tabular representation of players' utilities for each combination of strategies.

    | Player A \ Player B | Strategy I | Strategy II | | :--- | :--- | :--- | | Strategy I | (a, a') | (b, b') | | Strategy II | (c, c') | (d, d') |

  • Pure Strategy: A single, deterministic choice.

  • Mixed Strategy: Probability distribution over pure strategies.

  • Nash Equilibrium (NE): A set of strategies where no player can unilaterally improve their payoff by changing their strategy, given others' strategies.

    • Example (Penalty Kick from Nov 2023 paper):

      | Kicker \ Goalie | Left | Right | | :--- | :--- | :--- | | Left | 1.4, 0.6 | 1.5, 0.5 | | Right | 1.7, 0.4 | 1.5, 0.4 |

      • Kicker's Best Response: If Goalie goes Left → Kicker prefers Right (1.7 > 1.4). If Goalie goes Right → Kicker prefers Left (1.5 = 1.5, indifferent).

      • Goalie's Best Response: If Kicker goes Left → Goalie prefers Left (0.6 > 0.5). If Kicker goes Right → Goalie prefers Right (0.4 = 0.4, indifferent).

      • Mixed Strategy NE: Solve for probabilities where each player is indifferent. Let p = prob Kicker kicks Left, q = prob Goalie dives Left.

        • Kicker indifferent: 1.4q + 1.5(1-q) = 1.7q + 1.5(1-q) → q = 0.5.

        • Goalie indifferent: 0.6p + 0.4(1-p) = 0.5p + 0.4(1-p) → p = 0.5.

        • NE: (Kicker: 0.5 Left, 0.5 Right; Goalie: 0.5 Left, 0.5 Right).

8.2 Search Algorithms for Games

  • Minimax Algorithm: For two-player, zero-sum, perfect-information games.

    • Idea: MAX (AI) tries to maximize score, MIN (opponent) tries to minimize it. Assume opponent plays optimally.

    • Process: Recursively explore game tree to terminal states (win/loss/draw). Back up values: MAX node takes max of children, MIN node takes min.

    • Evaluation Function: Heuristic function f(n) estimating utility of non-terminal state n (e.g., material balance in chess).

  • Alpha-Beta Pruning: Optimization of Minimax. Prunes branches that cannot affect final decision.

    • α = best (highest) value found so far for MAX along the path.

    • β = best (lowest) value found so far for MIN along the path.

    • Prune a branch when α >= β (current node's value cannot improve parent's decision).

  • A Pathfinding Algorithm:*

    • Idea: Best-first search using heuristic h(n) (estimated cost to goal) + g(n) (actual cost from start).

    • Evaluation: f(n) = g(n) + h(n).

    • Requirement: h(n) must be admissible (never overestimates true cost) and preferably consistent for optimality.

    • Example: Grid pathfinding with Manhattan distance as h(n).

  • Breadth-First Search (BFS) for Pathfinding:

    • Explores all nodes at current depth before moving deeper. Guarantees shortest path in unweighted graph.

    • Implementation (Queue-based):

      
      from collections import deque
      
      def bfs(start, goal, get_neighbors):
      
          queue = deque([(start, [start])])
      
          visited = {start}
      
          while queue:
      
              node, path = queue.popleft()
      
              if node == goal: return path
      
              for neighbor in get_neighbors(node):
      
                  if neighbor not in visited:
      
                      visited.add(neighbor)
      
                      queue.append((neighbor, path + [neighbor]))
      
          return None  # No path
      
      

8.3 AI Architecture for Games

  • Rule-Based Systems: Uses "IF-THEN" rules to encode expert knowledge.

    • Example: Pac-Man ghost AI: IF Pac-Man is in same corridor AND distance < 5 THEN move towards Pac-Man.
  • Finite State Machines (FSM): Agent defined by finite set of states and transitions triggered by events/conditions.

    • Guard-Thief Example (from Nov 2023 paper):

      
      [Guard] --(no thief visible)--> [Stand Guard]
      
      [Stand Guard] --(thief visible & weak)--> [Fight]
      
      [Stand Guard] --(thief visible & strong)--> [Flee]
      
      [Fight] --(losing)--> [Flee]
      
      [Flee] --(escape complete)--> [Stand Guard]
      
      
  • Behavior Trees vs FSMs:

    | | FSM | Behavior Tree | | :--- | :--- | :--- | | Structure | States & Transitions (cyclic graph). | Tree of Nodes (Action, Condition, Sequence, Selector, Parallel). | | Control Flow | Explicit transitions (can be complex). | Implicit via node execution logic (tick-based). | | Extensibility | Adding new behavior requires modifying transitions (spaghetti). | Modular; add new subtree without changing existing ones. | | Readability | Can become hard to follow with many states. | Hierarchical, more intuitive for complex AI. | | Popularity | Traditional. | Modern standard (e.g., in Halo, The Last of Us). |

  • Model of Game AI: Typically a layered architecture:

    1. Decision Layer: High-level strategy (e.g., choose to attack/defend). Uses GOAP (Goal-Oriented Action Planning) or Behavior Trees.

    2. Navigation Layer: Pathfinding (A*), steering behaviors.

    3. Animation/Execution Layer: Plays animations, moves body according to navigation commands.

  • Board Game Theory: Focuses on combinatorial game theory (CGT). Analyzes game states as combinatorial objects. Concepts: Game tree complexity, Zermelo's theorem (in finite, perfect-information games, one player has a winning strategy or both can force a draw), retrograde analysis (solving endgames by working backward).

8.4 Movement and Coordination

  • Static vs Kinematic Representation in 3D:

    • Static (Kinematic): Describes position, orientation, scale at a single instant. No velocity/acceleration. Used for keyframes, poses.

    • Kinematic (Dynamic): Describes motion over time: position, velocity, acceleration, forces. Used for physics-based animation, steering.

  • Components of Coordinated Movement:

    1. Pathfinding: Global route from A to B (A*).

    2. Steering: Local adjustments to follow path, avoid obstacles, align velocity (e.g., Reynolds' steering behaviors: seek, flee, arrive, obstacle avoidance).

    3. Animation: Playing appropriate locomotion animations (walk, run, turn) based on speed/direction.

    4. Body Orientation: Aligning character's facing direction with movement direction (using "look where you're going").

  • Movement Algorithm Structure (Flowchart):

    
    [Start]
    
      |
    
      v
    
    [Get Target Position] --> [Pathfind (A*) to get path] --> [Follow Path (Steering)]
    
      |                                                               |
    
      v                                                               v
    
    [Is Target Reached?] <--- [Update Position/Orientation] <--- [Apply Forces]
    
      |
    
      +--Yes--> [Stop / Play Idle Animation]
    
      |
    
      +--No--> [Loop]
    
    
  • Stages of Motor Learning (Fitts & Posner):

    1. Cognitive Stage: Understand task, high error, conscious control.

    2. Associative Stage: Error decreases, refine movements, less conscious.

    3. Autonomous Stage: Skill becomes automatic, low error, minimal conscious attention.

8.5 Time Series Forecasting in Games

  • Average-Based Fuzzy Time Series:

    1. Partition universe of discourse into intervals.

    2. Define fuzzy sets (e.g., Low, Medium, High) with membership functions.

    3. Fuzzify historical data (which interval/level?).

    4. Establish fuzzy logical relationships (e.g., A_t → A_{t+1}).

    5. Forecast: For current fuzzy state A_t, find all A_t → A_{t+1} rules, defuzzify (e.g., take average of midpoints of A_{t+1} intervals).

  • Markov Chain Based on Modified Frequency Partitioning:

    1. Partition state space (e.g., player positions, health levels) based on frequency of occurrence (more states for frequent regions).

    2. Build transition matrix P by counting transitions between states in historical data.

    3. Forecast next state: S_{t+1} = argmax_j P(S_t = i, S_{t+1} = j) (most probable next state).

    • Flowchart: Data → Frequency-based Partitioning → Count Transitions → Build Transition Matrix → Predict via max P(i,j).

9. Model Evaluation and Validation

Precision and Recall (Classification):

  • Precision: Of all predicted positives, how many are correct? TP / (TP + FP). "How precise are my positive predictions?"

  • Recall: Of all actual positives, how many did I find? TP / (TP + FN). "How many true positives did I recall?"

  • Example (Disease Detection):

    • High Precision: Few false alarms (good if treatment is harsh).

    • High Recall: Few missed cases (critical for fatal diseases).

    • F1-Score: Harmonic mean: F1 = 2 * (Precision * Recall) / (Precision + Recall).

Other Evaluation Methods for Classifiers:

Metric Formula Focus
Accuracy (TP+TN) / Total Overall correctness (misleading if imbalanced).
Confusion Matrix Table of TP, FP, TN, FN. Foundation for all other metrics.
Specificity TN / (TN + FP) True negative rate.
ROC-AUC Area under ROC curve (TPR vs FPR). Model's ability to discriminate across thresholds.

Overfitting and Underfitting:

Underfitting Overfitting
Cause Model too simple (high bias). Model too complex (high variance).
Train Error High Low
Test Error High High
Visual Poor fit to training data. Perfect/near-perfect fit to training data, poor generalization.
Mitigation Use more complex model, add features, reduce regularization. Get more data, use regularization (L1/L2), simplify model (prune tree), cross-validation, early stopping.

Cross-Validation Techniques:

  • k-Fold CV: Standard method (see Unit 4).

  • Stratified k-Fold: Maintains class distribution in each fold (for classification).

  • Leave-One-Out (LOO): k = n. High variance, computationally expensive.

  • Time Series CV: Forward chaining (train on past, test on future) to respect temporal order.

Evaluation of Regression Models:

  • MSE: (1/m) Σ(y - ŷ)². Sensitive to outliers.

  • RMSE: √MSE. In same units as target.

  • MAE: (1/m) Σ\|y - ŷ\|. More robust to outliers.

  • R² (Coefficient of Determination): Proportion of variance explained. 1 - (SS_res / SS_tot).

Mini-batch Gradient Descent (as Optimization):

  • Process: At each iteration, randomly select a mini-batch (e.g., 32, 64, 128 samples). Compute gradient on this batch and update parameters.

  • Advantages over Batch GD:

    • Faster convergence: More frequent updates.

    • Can escape shallow local minima/saddle points due to noise in gradient estimate.

    • Works well with modern hardware (GPU vectorization).

  • Disadvantages: Noisy convergence path, requires tuning batch size.


10. Applications and Case Studies

Machine Learning in Graphs, Maps, and Map Searching:

  • Graph ML: Node classification (e.g., user profiling), link prediction (friend suggestions), graph classification (molecule property prediction). Uses GCNs, GATs.

  • Maps/Map Searching: Shortest path (A*, Dijkstra), traffic prediction (time-series models), ETA estimation (regression on historical speeds), geospatial clustering (DBSCAN for hotspots), image-based map updates (CV for road changes).

Stable Marriages Algorithm in ML Applications:

  • Problem: Match two sets (e.g., users and items, jobs and candidates) based on preferences.

  • Gale-Shapley Algorithm: Propose-defer mechanism guaranteeing a stable matching (no pair prefers each other over current match).

  • ML Applications: Recommendation systems (matching users to products), job-resume matching, organ donation pairing.

Prediction of Preterm Birth using ML:

  • Goal: Early identification of high-risk pregnancies.

  • Data: Electronic Health Records (EHR), biomarkers (cervical length, fetal fibronectin), genomics, demographics.

  • Models: Logistic regression, Random Forest, RNNs/LSTMs for longitudinal data.

  • Challenges: Class imbalance (preterm is rare), data heterogeneity, interpretability for clinicians.

Interconnectedness on Personal Genomes in ML:

  • Goal: Understand gene-gene and gene-environment interactions influencing traits/diseases.

  • Data: SNP arrays, whole-genome sequencing, phenotypic data.

  • ML Techniques: ** epistasis detection** (searching for interacting SNP pairs), network medicine (building disease-gene networks), polygenic risk scores (aggregating small effects).

  • Challenge: High dimensionality (p >> n), complex non-linear interactions.

Decision Trees in Game Development:

  • Applications: NPC behavior decision-making (e.g., combat tactics, dialogue choices), procedural content generation (rule-based branching narratives), difficulty scaling.

  • Advantages: Human-readable rules, fast execution at runtime, easy to tweak by designers.

  • Disadvantages: Can become brittle with many rules; often combined with other techniques (FSMs, utility systems).

Data Products in Predictive Analytics (Examples from Strategy):

  • Descriptive: Real-time dashboard showing server health metrics.

  • Predictive: Churn prediction model outputting a probability score for each customer.

  • Prescriptive: Dynamic pricing engine that sets optimal price for a product based on demand forecast, competitor prices, and inventory levels.

  • Diagnostic: Root cause analysis tool that, after a system failure, identifies the most likely component failures based on error logs.

Go to where you left off?

Quick Add to Notes

Save questions, your own notes and screenshots into notes filed by unit. It takes a free account.

Create free account

Have an account? Log in