Gradient descent is the most popular optimization strategy used and Machine Learning and Deep Learning. Follow along and learn 17 Most Common Gradient Descent Interview Questions (ANSWERED) that help you pass your next ML & Data Science Interview.
Gradient descent is an optimization algorithm that’s used when training a machine learning model and is based on a convex function and tweaks its parameters iteratively to minimize a given function to its local minimum (that is, slope = 0).
For a start, we have to select a random bias and weights, and then iterate over the slope function to get a slope of 0.
The way we change update the value of the bias and weights is through a variable called the learning rate. We have to be wise on the learning rate because choosing:
Where:
The applicability of batch or stochastic gradient descent depends on the error manifold expected.
One benefit of SGD is that it's computationally a whole lot faster. Large datasets often can't be held in RAM, which makes vectorization much less efficient. Rather, each sample or batch of samples must be loaded, worked with, the results stored, and so on. Minibatch SGD, on the other hand, is usually intentionally made small enough to be computationally tractable. Usually, this computational advantage is leveraged by performing many more iterations of SGD, making many more steps than conventional batch gradient descent. This usually results in a model that is very close to that which would be found via batch gradient descent, or better.
The Gradient Descent works by starting with random values for each coefficient in the linear regression model.
To answer the given question, let’s first understand the difference between these two techniques.
In Gradient descent:
O(kn²).Meanwhile, in Ordinary Least Squares:
O(n³).Clearly, if we have large training data, ordinary least squares is not preferred for use due to very high time complexity but for small values of n, ordinary least squares is faster than gradient descent so it would be preferred the classical approach.
Mean absolute error (MAE): calculates the absolute difference between actual and predicted values. It can be used when we want that our model be robust to outliers, but this metric has the disadvantage of not being differentiable so we can't use it if we want to apply optimizers like Gradient descent.
Mean squared error (MSE): calculates the squared difference between actual and predicted value. We can use this metric if we want to give bigger penalization to outliers and apply optimizers who require differentiation. MSE is a differentiable function that makes it easy to perform mathematical operations in comparison to a non-differentiable function like MAE.
Root mean squared error (RMSE): This is simply the square root of mean squared error. This metric is not so robust to outliers as the mean absolute error but it has the advantage to be differentiable so we can use it if we want to apply gradient descent to minimize losses.
When to use one depends on your loss function:
There are three types of gradient descent methods based on the amount of data used to calculate the gradient:
A few types of stopping conditions are as follows:
Other possible options for finding lower minima in a reasonable amount of time could include:
Prepare for AI developer and engineer interviews with 19 answered OpenClaw questions covering Gateway architecture, channels, agent workspaces, memory, MCP, model failover, multi-agent routing, security, sandboxing, approvals, and remote operations....
Prepare for AI agent developer interviews with 15 Model Context Protocol (MCP) questions covering tools, resources, prompts, JSON-RPC, transports, roots, sampling, security, and practical MCP server design....
Amazone runs the internet as we know it. Amazon Web Services (AWS) offers a comprehensive suite of machine learning (ML) services that cater to various needs and expertise levels. Follow along and learn the 23 most common AWS machine-learning intervi...