1BV70 - Lecture 3v1- Predictive modeling

📚 1BV70 - Lecture 3v1- Predictive modeling.pdf

Brief overview

This document introduces predictive modeling techniques, focusing on fitting models to data for classification and probability estimation. Understanding these methods is crucial for building systems that can learn from data and make informed predictions.

Key points

  • Overview of course topics including linear regression, logistic regression, and gradient descent.

  • Exploration of linear discriminant functions and the maximum margin classifier for data fitting.

  • Detailed explanation of class probability estimation using logistic regression and the sigmoid function.

  • In-depth coverage of gradient descent optimization, including its variants and learning rate.

  • Introduction to neural networks, representation learning, and their application in complex mappings.


1. Course overview and summary

1.1 Introduction to predictive modeling

  • This course covers predictive modeling techniques.

  • Key topics include fitting models to data, linear regression, and logistic regression.

  • We will also explore gradient descent and neural networks.

  • The course delves into linear discriminant functions and classifiers.

  • A significant focus is on finding optimal lines to fit data. , 1 2.

1.2 Linear discriminant functions

  • A linear discriminant function is used for classification.

  • It defines a boundary to separate different classes.

  • Finding an optimal line requires careful consideration of how to fit the data. , 5 6.

1.3 The maximum margin classifier

  • The maximum margin classifier aims to find the widest possible separation between classes.

  • It fits the "fattest bar" between distinct groups of data.

  • The decision boundary is the center line within this widest bar.

  • The distance between parallel lines defining this bar is the margin.

  • Maximizing the margin makes the classifier more robust.

  • This is especially true for new, unseen data near the decision boundary. 8.

📝 Example: Imagine sorting fruits by size and color. A maximum margin classifier would draw the widest possible "buffer zone" to clearly distinguish between apples and oranges, making it less likely to misclassify a fruit if its size or color is slightly ambiguous.

1.4 Handling misclassified points and loss functions

  • Loss functions penalize training points for being on the wrong side of the decision boundary.

  • They quantify the error when a point falls outside the margin or on the incorrect side.

Loss function

Behavior

Hinge loss

Positive if inside the margin or on the wrong side; increases linearly

Zero-one loss

Penalizes any misclassification

Least-squared error

Penalizes errors quadratically

, 10 9.

🔑 Important: The choice of loss function significantly impacts how a model learns to separate data. Hinge loss and zero-one loss are directly related to classification boundaries, while least-squared error is more typical of regression.

🔑 Important: The maximum margin classifier is a foundational concept for support vector machines (SVMs), emphasizing robustness by creating the largest possible gap between classes.

2. Class probability estimation and logistic regression

2.1 Why linear models are not ideal for probability estimation

  • Linear models: produce outputs with an unlimited range (-∞ to +∞).

  • Probabilities must stay within a strict range of 0 to 1.

  • Using a linear model for probability estimation would violate this fundamental constraint.

2.2 Odds and log-odds for probability

  • Odds: the ratio of an event's probability to the probability of it not occurring.

    • Formula: textOdds=fracp1−p\\text{Odds} = \\frac{p}{1 - p}
  • Log-odds: the natural logarithm of the odds.

    • Formula: textLog−odds=lnleft(fracp1−pright)\\text{Log-odds} = \\ln\\left(\\frac{p}{1 - p}\\right)
  • Log-odds can range from -∞ to +∞, aligning with the output of linear models.

Probability (p)

Odds (p / 1-p)

Log-odds (ln(Odds))

0.999

999

6.9

0.9

9

2.19

0.5

1

0

0.01

0.0101

-4.6

0.001

0.001001

-6.9

Key relationship: Log-odds can be directly modeled by linear functions, while probabilities cannot.

2.3 Logistic regression model

  • Logistic regression models the log-odds as a linear combination of independent variables.

  • The formula for the estimated probability of class membership, hatp\\hat{p}, is derived from this linear relationship.

lnleft(frachatp1−hatpright)=mathbfwTmathbfx\\ln\\left(\\frac{\\hat{p}}{1 - \\hat{p}}\\right) = \\mathbf{w}^T \\mathbf{x}

  • This equation can be rearranged to solve for hatp\\hat{p}.

hatp=g(mathbfwTmathbfx)\\hat{p} = g(\\mathbf{w}^T \\mathbf{x})

  • Here, g(cdot)g(\\cdot) is the sigmoid function, which maps any real number to a value between 0 and 1.

2.4 The sigmoid function

  • The sigmoid function, also known as the logistic function, is essential for probability estimation.

  • It takes any real-valued input and compresses it into the range (0, 1).

sigma(z)=frac11+e−z\\sigma(z) = \\frac{1}{1 + e^{-z}}

  • The "S" shape of the sigmoid curve ensures that the output is always a valid probability.

📝 Example: If the linear model output mathbfwTmathbfx\\mathbf{w}^T \\mathbf{x} is large and positive, the sigmoid outputs a value close to 1. If it's large and negative, it outputs a value close to 0.

Property

Value / Range

Domain

(-∞, +∞)

Range

(0, +1)

Monotonicity

Increasing

Continuity

Continuous

2.5 Objective function for logistic regression

  • The goal is to estimate the model parameters (mathbfw\\mathbf{w}) such that the predicted probabilities accurately reflect the observed data.

  • For binary classification, the target variable has values 0 or 1.

  • Ideally, the model should predict a probability of 1 for positive examples and 0 for negative examples.

🔑 Important: Real-world data rarely allows for perfect probability estimation (e.g., predicting exactly 0 or 1).

  • Maximum Likelihood Estimation (MLE) is used to find the best parameters.

  • MLE finds the parameters that maximize the "likelihood" of observing the actual labeled data given the model's probability estimates.

2.6 Logistic regression versus tree-based models

  • Both logistic regression and classification trees are used for classification.

  • They differ in the type of decision boundaries they create.

Classifier

Decision Boundary Type

Attribute Usage

Classification Tree

Perpendicular to axes; "piecewise" linear segments.

Selects one attribute at a time for splitting.

Linear Classifier

Any direction or orientation; a single hyper-plane.

Uses a weighted combination of all attributes.

  • Logistic regression offers a single, global decision surface with flexible orientation.

  • Classification trees create multiple local decision regions by recursively splitting the feature space.

2.7 Wrap-up example: Logistic regression

  • Linear Regression predicts a continuous value (e.g., a test score from 0 to 100).

  • Logistic Regression predicts the probability of a binary outcome (e.g., pass or fail).

📝 Example: If a logistic regression model predicts a probability of 0.4 for a student passing, it should be categorized as "Failed". (Assuming a threshold of 0.5 for classification).

  • Parameter Estimation:

    • Linear Regression: Typically uses Mean Squared Error.

    • Logistic Regression: Uses Maximum Likelihood Estimation.

  • Gradient descent is often used to find the optimal parameters for logistic regression cost functions.

🔑 Important: Logistic regression outputs probabilities that are then typically thresholded (e.g., at 0.5) to make a final binary classification.

3. Gradient descent optimization

3.1 Introduction to gradient descent

  • Gradient descent is an optimization algorithm used to find the minimum of a differentiable function.

  • It helps machine learning models find parameter values that minimize a cost function.

  • This method is more efficient than the least squares method, especially for many variables.

  • It performs fewer calculations far from the optimal solution and more near it.

3.2 Understanding the gradient

  • The gradient measures how much a function's output changes with small input changes.

  • It indicates the direction and magnitude of the steepest ascent of a function.

  • In machine learning, it measures the change in error with respect to changes in model weights.

  • A higher gradient means a steeper slope, allowing a model to learn faster.

The gradient points uphill; gradient descent takes steps downhill.

3.3 How gradient descent works

  • Gradient descent iteratively adjusts model parameters (like weights, ww, and bias, bb) to minimize a cost function, J(w,b)J(w,b).

  • It starts with random parameter values.

  • At each step, it moves in the direction of the steepest decrease, calculated using partial derivatives (the negative gradient).

  • This process continues until it reaches a point where the cost function is minimal.

The horizontal axes represent parameters (ww, bb), and the vertical axis shows the cost function J(w,b)J(w, b).

3.4 The role of the learning rate

  • The learning rate (alpha\\alpha) controls the size of each step taken towards the minimum.

  • A very large learning rate can cause the algorithm to overshoot the minimum and fail to converge.

  • A very small learning rate can lead to extremely slow learning and convergence.

Choosing the right learning rate is crucial for efficient convergence.

  • Visualizing convergence: Plotting the cost function against training steps helps verify if the learning rate is effective.

    • A good learning rate shows the cost decreasing as training progresses.

3.5 Variants of gradient descent

Gradient descent has several variants, differing in how much data they use to compute the gradient for each update.

Variant

Data used for gradient calculation

Updates parameters

Pros

Cons

Batch gradient descent

Entire dataset

After processing all data

Stable convergence, stable gradient

Memory and computation inefficient

Stochastic gradient descent

Single training example

After each example

Efficient, frequent updates

Noisy gradient

Mini-batch gradient descent

A small batch of data

After processing each batch

Robust, efficient

(Implied: balance between others)

Batch GD is slow but stable; SGD is fast but noisy; Mini-batch GD balances both.

  • The trajectory of each variant can look different as they approach the minimum. Batch GD follows a smoother path, while SGD can be erratic.

🔑 Important: Gradient descent is a fundamental optimization technique in machine learning, essential for training models by minimizing errors. Understanding its variants and the learning rate is key to effective model performance.

4. Neural networks and representation learning

4.1 Introduction to neural networks

Neural networks are powerful, flexible functions. They have many parameters that allow them to learn complex patterns.

These networks are built by layering simpler functions together. This makes them compositional.

The basic structure involves nodes, also called neurons, connected in an acyclic graph.

  • Brain analogy: Neurons receive signals, sum them, and "fire" if a threshold is met. This "firing" is governed by an activation function.

  • Parameters: In neural networks, these are the weights (ww) and biases (bb). They are adjusted during training.

4.1.1 Feed-forward pass

The feed-forward pass is how a neural network makes a prediction. It starts with input data and moves through the network layer by layer.

Each neuron calculates a weighted sum of its inputs, adds a bias, and then applies an activation function.

  • Summation: For a neuron h_ih\_i, the sum (zz) is calculated as: z_h_i=sum_jw_jix_j+b_iz\_{h\_i} = \\sum\_{j} w\_{ji} x\_j + b\_i where x_jx\_j are inputs and w_jiw\_{ji} are weights.

  • Activation: The sum is then passed through an activation function to introduce non-linearity. The output of a neuron oo is: o_h_i=textactivation(z_h_i)o\_{h\_i} = \\text{activation}(z\_{h\_i})

4.1.2 Neural network structure and parameters

A neural network is an acyclic graph of connected nodes. Nodes in adjacent layers are typically fully connected.

Nodes within the same layer do not connect to each other.

  • Input layer: Receives the initial data. Its size is determined by the number of input features.

  • Hidden layers: Perform intermediate computations. They introduce non-linearity.

  • Output layer: Produces the final prediction. Its size depends on the task (e.g., number of classes).

Learnable parameters: These are the weights and biases that the network learns.

Component

Description

Calculation Example (based on image)

Number of weights

Connections between neurons.

$[2 \times 3 + [3 \times 2 = 12$

Number of biases

Added to the weighted sum in each neuron.

$3 + 2 = 5$

Total parameters

Sum of weights and biases.

$12 + 5 = 17$

49.

4.1.3 Activation functions

Activation functions introduce non-linearity into the network. Without them, a neural network would simply be a linear function.

They allow the network to learn complex relationships in the data. Common activation functions include ReLU (Rectified Linear Unit) and Sigmoid.

📝 Example: Applying an activation function to the computed sum zz transforms it into the neuron's output oo. For instance, using ReLU means o=max(0,z)o = \\max(0, z).

4.1.4 Softmax for classification

The SoftMax function is typically used in the output layer for classification tasks. It converts raw output scores into probabilities that sum to 1.

This makes the output interpretable as a probability distribution over classes.

🔑 Important: SoftMax ensures that the outputs for a classification problem are in the range and sum to 1, representing probabilities 1.

58.

4.1.5 Backpropagation

Backpropagation is the process of adjusting the network's weights and biases to improve its predictions. It involves calculating the error between the predicted output and the true label.

This error is then propagated backward through the network to determine how much each parameter contributed to the error.

  • Error calculation: The difference between the network's prediction and the actual target is quantified.

  • Gradient calculation: The gradient of the error with respect to each weight and bias is computed.

  • Parameter update: Weights and biases are adjusted in the direction that minimizes the error.

The update rule for a weight W_xW\_x is: W_x\*=W_x−alphafracpartialEpartialW_xW\_x^\* = W\_x - \\alpha \\frac{\\partial E}{\\partial W\_x} where W_x\*W\_x^\* is the new weight, W_xW\_x is the old weight, alpha\\alpha is the learning rate, and fracpartialEpartialW_x\\frac{\\partial E}{\\partial W\_x} is the partial derivative of the error (EE) with respect to the weight W_xW\_x. 62.

4.2 Representation learning

Representation learning aims to automatically discover useful features or representations from raw data. Traditional machine learning often requires manual feature engineering.

Representation learning automates this process. It breaks down complex mappings into a series of nested, simpler mappings through layers.

🔑 Important: Neural networks are a prime example of representation learning, as they learn hierarchical features from data.

The goal is to learn representations that make subsequent tasks, like classification or prediction, easier. The human brain is excellent at this, understanding various versions of inputs like digits.

Computers struggle with raw sensory data. 40.

🔑 Important: Representation learning decomposes complex problems into sequences of simpler problems solved by successive layers. 41.

🔑 Important: The most exam-relevant insight is that neural networks learn by iteratively adjusting parameters (weights and biases) through backpropagation to minimize prediction errors, effectively learning data representations layer by layer.

© 2026 Maeve. All rights reserved. This content is protected by copyright.

See also