What is Optimization?
What is it?
Optimization means finding the input to a function that makes its output as small (or as large) as possible.
In machine learning, we always optimize the same kind of thing: we search for the model's parameters that make the errors as small as possible.
Why we need it
Every machine learning model has numbers inside it called parameters β for example, the slope and intercept of a line, or the weights of a neural network.
Different parameter values give different predictions. Some predictions are close to the truth. Others are far off.
We need a way to find the parameter values that give the best predictions. That is what optimization does: it searches for the best parameters by minimizing a measure of error called the loss.
Without optimization, we would have to try every possible combination of parameter values by hand β which is impossible for real models with millions of parameters.
Explained in detail
Imagine you are tuning a radio. You turn the dial and listen to the signal. When the signal is clear, you stop. You were minimizing the noise.
The dial is the parameter. The noise is the loss. Turning the dial until the signal is clearest is optimization.
In math, we write a function where:
- is the parameter (what we can change)
- is the loss (what we want to minimize)
The question is: what value of makes the smallest?
That point is called the minimum. At the minimum, the function stops decreasing and starts increasing. The slope is exactly zero.
Two kinds of minimum:
- Global minimum β the absolute lowest point of the entire function.
- Local minimum β a point that is lower than its neighbors, but not the lowest overall. The function could be even lower somewhere else.
Simple functions like a parabola have one global minimum. Real ML loss functions are bumpy and have many local minima. Modern optimizers handle this surprisingly well in practice.
Loss Landscape
Drag the orange dot to explore the loss at different parameter values. The green dashed line marks the global minimum.
What to try
- Drag the orange dot left and right along the curve to explore the loss at different parameter values.
- Watch the Loss value in the panel update as you move.
- Notice the green dashed line marks the global minimum β the lowest possible loss.
- Try the "Bumpy" preset to see a function with local minima. Can you find all the valleys?
- Try "Convex" to see a clean parabola β one minimum, easy to find. Most real loss functions are more like "Bumpy".
Notes & Formula
The optimization problem in ML:
returns the input that makes the function smallest. returns the output (the smallest value itself). We want β we want the best parameters, not just the best loss score.
Common mistake: thinking optimization always finds the global minimum. In real ML, we usually find a good local minimum β and that is enough.
Quiz
π§©
Ready to test yourself?
10 questions Β· explanations shown after
Mastered this concept?
Tick this box when you feel confident explaining it.
Topic Resources
ποΈ
No notes uploaded for this topic yet
Lecture notes, summaries, and notebook exercises will be added here. You can also view or contribute notes on GitHub.
Was this clear?