# Optimization and Gradient Descent

> Loss landscapes, convexity, gradient descent and its stochastic variants: how model parameters are actually found. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/machine-learning/optimization
Last updated: 2026-11-28

Loss landscapes, convexity, gradient descent and its stochastic variants: how model parameters are actually found.

Intermediate · about 10 hours · difficulty 3/5

Learn first: [Calculus and Gradients](https://www.internhack.in/roadmaps/tracks/machine-learning/calculus-gradients)

Fitting a model means solving an optimization problem: find parameters that minimize a loss. A few models have closed-form solutions, but almost everything else uses iterative, gradient-based methods.

### Concepts

- **Objective functions**: loss plus regularization terms.
- **Convex versus non-convex**: linear and logistic regression have one global minimum; neural networks do not, yet still train well in practice.
- **Gradient descent**: repeat `theta = theta - lr * grad`. The learning rate is the most important knob.
- **Stochastic and mini-batch gradient descent**: noisy but cheap gradient estimates from small batches; the default for large data.
- **Momentum and adaptive methods** (preview): SGD with momentum, RMSProp, Adam. Covered in depth in the deep learning section.
- **Constrained optimization and Lagrange multipliers**: conceptual level, for understanding SVMs.

### Diagnosing

Plot the loss per iteration. Divergence or oscillation means the learning rate is too high; a flat slow curve means too low or poorly scaled features. Feature scaling dramatically speeds up gradient descent.

**Good enough to move on** when you can implement mini-batch gradient descent for logistic regression and explain the effect of learning rate and batch size on the loss curve.

## Key concepts

- **Loss functions and objectives**
- **Convexity**
- **Batch gradient descent**
- **Stochastic and mini-batch GD**
- **Learning rate effects**
- **Momentum and Adam preview**
- **Lagrange multipliers**

## Mini project

Implement batch, mini-batch and stochastic gradient descent for logistic regression on the Breast Cancer Wisconsin dataset and plot loss curves for three learning rates on one figure.

## Check yourself

Your loss goes to NaN after a few iterations. Name two likely causes and how you would check each.

## Free resources

- [Google ML Crash Course (gradient descent module)](https://developers.google.com/machine-learning/crash-course) (Google)
- [Dive into Deep Learning: Optimization Algorithms](https://d2l.ai/chapter_optimization/index.html) (d2l.ai)

Previous: [Statistics for Data Science](https://www.internhack.in/roadmaps/tracks/machine-learning/statistics) · Next: [Exploratory Data Analysis](https://www.internhack.in/roadmaps/tracks/machine-learning/exploratory-data-analysis)

## More in The Math Behind the Models

- [Linear Algebra for ML](https://www.internhack.in/roadmaps/tracks/machine-learning/linear-algebra)
- [Calculus and Gradients](https://www.internhack.in/roadmaps/tracks/machine-learning/calculus-gradients)
- [Probability for ML](https://www.internhack.in/roadmaps/tracks/machine-learning/probability)
- [Statistics for Data Science](https://www.internhack.in/roadmaps/tracks/machine-learning/statistics)
- [Optimization and Gradient Descent](https://www.internhack.in/roadmaps/tracks/machine-learning/optimization)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Machine Learning Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/machine-learning)
