Loss Function and Optimization in Supervised Learning

 

Loss Function and Optimization in Supervised Learning


🔹  Overview

In supervised learning, we want to learn a function:

f(x;θ)yf(x; \theta) \rightarrow y

👉 The key questions:

  • How good is the prediction? → Loss Function
  • How do we improve the model? → Optimization

🔹Loss Function 

🔹Definition

A loss function measures the difference between actual output and predicted output.

L(y,y^)L(y, \hat{y})

Where:

  • yy → true value
  • y^=f(x;θ)\hat{y} = f(x; \theta)→ predicted value

🔹Role of Loss Function

👉 It acts as a guide for learning

  • Quantifies error
  • Provides objective for optimization
  • Helps compare models

🔹Types of Loss Functions


🟦 1. Regression Loss Functions

📌 Mean Squared Error (MSE)

L=(yy^)2L = (y - \hat{y})^2
  • Penalizes large errors
  • Smooth and differentiable

📌 Mean Absolute Error (MAE)

L=yy^L = |y - \hat{y}|
  • Robust to outliers

🟩 2. Classification Loss Functions

📌 0–1 Loss

L={0if correct1if wrongL = \begin{cases} 0 & \text{if correct} \\ 1 & \text{if wrong} \end{cases}

📌 Cross-Entropy Loss (Very Important)

L=ylog(y^)L = - \sum y \log(\hat{y})
  • Used in logistic regression and neural networks

📌 Hinge Loss (SVM)

L=max(0,1yy^)L = \max(0, 1 - y\hat{y})

🔹 Properties of Good Loss Functions

  • Differentiable
  • Convex (for easy optimization)
  • Reflects real-world cost

🔹Optimization 

🔹 Definition

Optimization is the process of finding model parameters that minimize the loss function.


🔹 Objective Function

minθR(θ)\min_{\theta} R(\theta)

🔹 Gradient Descent

📌 Idea:

Move parameters in direction of steepest decrease of loss

θ=θηR(θ)\theta = \theta - \eta \nabla R(\theta)

Where:

  • η\eta → learning rate
  • R(θ)\nabla R(\theta) → gradient

🔹 Types of Gradient Descent

🟦 1. Batch Gradient Descent

  • Uses entire dataset

🟩 2. Stochastic Gradient Descent (SGD)

  • Uses one data point

🟨 3. Mini-Batch Gradient Descent

  • Uses small subsets

🔹Learning Rate (Very Important)

  • Too small → slow learning
  • Too large → divergence

🔹 Convergence

👉 Optimization stops when:

  • Loss stops decreasing
  • Gradient ≈ 0

🔹 Local vs Global Minimum

  • Global minimum → best solution
  • Local minimum → suboptimal

🔹 Regularization (Connected to MAP)

Add penalty to avoid overfitting: 

R(θ)+λθ2R(\theta) + \lambda ||\theta||^2

🔹Connection Between Loss and Optimization

👉 Loss defines what to minimize
👉 Optimization defines how to minimize


🔹Example 

📌 Linear Regression

Model:

y^=wx+b\hat{y} = wx + b

Loss:

L=(yy^)2L = (y - \hat{y})^2

Optimization:

  • Use gradient descent
  • Update w,b

🔹Practical Challenges

  • Non-convex loss (neural networks)
  • Large datasets
  • Vanishing gradients

🔹Key Insights 

  • Learning = optimization problem
  • Choice of loss affects model behavior
  • Efficient optimization is crucial for large-scale data
  • Trade-off between accuracy and computational cost

📝 Summary 

Loss Function:

  • Measures prediction error
  • Defines objective

Optimization:

  • Minimizes loss
  • Finds best parameters

Key Equation:

minθ1nL(yi,f(xi))\min_{\theta} \frac{1}{n}\sum L(y_i, f(x_i))

Comments

Popular posts from this blog

Machine Learning PCCST503 Semester5 KTU CS 2024 Scheme - Dr Binu V P

Introduction to Machine Learning (ML)

Distinguishing Machine Learning from Traditional Programming