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:
-
Identify Business Problem & Define Success Metric: Clearly articulate the predictive goal (e.g., "reduce customer churn by 10%") and define Key Performance Indicators (KPIs).
-
Data Asset Assessment: Inventory available internal/external data sources. Evaluate quality (completeness, accuracy), volume, and accessibility.
-
Feasibility & Approach Selection: Determine if the problem is solvable with available data and tools. Choose between statistical modeling, machine learning, or rule-based systems.
-
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.
-
Deployment & Integration: Integrate the model into business workflows (e.g., API, dashboard, automated decision system). Ensure scalability and reliability.
-
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:
requestslibrary (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 (
@ornp.dot()), broadcasting, slicing. -
Matrix Inversion:
np.linalg.inv(A)computes the inverse of square matrixA. SolvesAx = bvianp.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_codeafter arequests.get(). Handle potentialNonereturns fromsoup.find().
3. Statistical Foundations and Data Preparation
Descriptive Statistics (NumPy):
-
Average (Mean):
np.mean(data) -
Variance:
np.var(data)(population by default, useddof=1for 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*IQRorQ3 + 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:
-
There exists a pattern (target function
f) to be learned. -
There is a large set of examples (training data) of this pattern.
-
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:
-
Partition data into
kequal folds. -
For each fold
i: Train on all folds excepti, validate on foldi. -
Average performance across
kruns. 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:
-
Define variables (
tf.Variable) and placeholders (tf.placeholder). -
Construct the model graph (e.g.,
y_pred = tf.matmul(X, W) + b). -
Define loss function (
tf.reduce_mean(tf.square(y_pred - y))). -
Choose optimizer (
tf.train.GradientDescentOptimizer(learning_rate)) and minimize loss. -
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_iis proportion of classiin setS. -
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):
-
Start with all training data at root.
-
Select the attribute with highest Information Gain.
-
Create a branch for each value of that attribute.
-
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 |
-
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 \]
-
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
lconnected to all neurons in layerl+1.
-
-
Learning Process:
-
Forward Propagation: Compute output layer prediction
\hat{y}from inputXthrough successive layer transformations:z = Wx + b,a = g(z). -
Compute Loss: Compare
\hat{y}to trueyusing loss function (e.g., Cross-Entropy, MSE). -
Backpropagation: Apply Chain Rule to compute gradient of loss w.r.t. each weight/bias. Propagates error backward from output to input.
-
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_jtarget,y_joutput,x_iinput. 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:
-
For
b = 1toB(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.
-
-
Final prediction: Average (regression) or majority vote (classification) of all
Btrees.
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 states'fromstaking actiona. -
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 usingmax_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):
-
Generate an episode using current policy
π_θ. -
For each step
tin episode, compute returnG_t. -
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 staten(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:
IFPac-Man is in same corridorANDdistance < 5THENmove towards Pac-Man.
- Example: Pac-Man ghost AI:
-
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:
-
Decision Layer: High-level strategy (e.g., choose to attack/defend). Uses GOAP (Goal-Oriented Action Planning) or Behavior Trees.
-
Navigation Layer: Pathfinding (A*), steering behaviors.
-
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:
-
Pathfinding: Global route from A to B (A*).
-
Steering: Local adjustments to follow path, avoid obstacles, align velocity (e.g., Reynolds' steering behaviors: seek, flee, arrive, obstacle avoidance).
-
Animation: Playing appropriate locomotion animations (walk, run, turn) based on speed/direction.
-
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):
-
Cognitive Stage: Understand task, high error, conscious control.
-
Associative Stage: Error decreases, refine movements, less conscious.
-
Autonomous Stage: Skill becomes automatic, low error, minimal conscious attention.
-
8.5 Time Series Forecasting in Games
-
Average-Based Fuzzy Time Series:
-
Partition universe of discourse into intervals.
-
Define fuzzy sets (e.g., Low, Medium, High) with membership functions.
-
Fuzzify historical data (which interval/level?).
-
Establish fuzzy logical relationships (e.g.,
A_t → A_{t+1}). -
Forecast: For current fuzzy state
A_t, find allA_t → A_{t+1}rules, defuzzify (e.g., take average of midpoints ofA_{t+1}intervals).
-
-
Markov Chain Based on Modified Frequency Partitioning:
-
Partition state space (e.g., player positions, health levels) based on frequency of occurrence (more states for frequent regions).
-
Build transition matrix
Pby counting transitions between states in historical data. -
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.