Why is Newton's method not widely used in machine learning? This is something that has been bugging me for a while, and I couldn't find any satisfactory answers online, so here goes:
After reviewing a set of lectures on convex optimization, Newton's method seems to be a far superior algorithm than gradient descent to find globally optimal solutions, because Newton's method can provide a guarantee for its solution, it's affine invariant, and most of all it converges in far fewer steps. Why is second-order optimization algorithms, such as Newton's method not as widely used as stochastic gradient descent in machine learning problems?
 A: For large dimensions, the Hessian is typically expensive to store and solving 
$Hd = g$ for a direction can be expensive. It is also more difficult to parallelise.
Newton's method works well when close to a solution, or if the Hessian is
slowly varying, but needs some tricks to deal with lack of convergence and
lack of definiteness.
Often an improvement is sought, rather than an exact solution, in which case
the extra cost of Newton or Newton like methods is not justified.
There are various ways of ameliorating the above such as variable metric or
trust region methods.
As a side note, in many problems a key issue is scaling and the Hessian
provides excellent scaling information, albeit at a cost. If one can approximate the Hessian, it can often improve performance considerably. To some extent, Newton's method provides the 'best' scaling in that it is
affine invariant.
A: More people should be using Newton's method in machine learning*. I say this as someone with a background in numerical optimization, who has dabbled in machine learning over the past couple of years.
The drawbacks in answers here (and even in the literature) are not an issue if you use Newton's method correctly. Moreover, the drawbacks that do matter also slow down gradient descent the same amount or more, but through less obvious mechanisms. 


*

*Using linesearch with the Wolfe conditions or using or trust regions prevents convergence to saddle points. A proper gradient descent implementation should be doing this too. The paper referenced in Cam.Davidson.Pilon's answer points out problems with "Newton's method" in the presence of saddle points, but the fix they advocate is also a Newton method. 

*Using Newton's method does not require constructing the whole (dense) Hessian; you can apply the inverse of the Hessian to a vector with iterative methods that only use matrix-vector products (e.g., Krylov methods like conjugate gradient). See, for example, the CG-Steihaug trust region method.

*You can compute Hessian matrix-vector products efficiently by solving two higher order adjoint equations of the same form as the adjoint equation that is already used to compute the gradient (e.g., the work of two backpropagation steps in neural network training).

*Ill conditioning slows the convergence of iterative linear solvers, but it also slows gradient descent equally or worse. Using Newton's method instead of gradient descent shifts the difficulty from the nonlinear optimization stage (where not much can be done to improve the situation) to the linear algebra stage (where we can attack it with the entire arsenal of numerical linear algebra preconditioning techniques). 

*Also, the computation shifts from "many many cheap steps" to "a few costly steps", opening up more opportunities for parallelism at the sub-step (linear algebra) level.
For background information about these concepts, I recommend the book "Numerical Optimization" by Nocedal and Wright.
*Of course, Newton's method will not help you with L1 or other similar compressed sensing/sparsity promoting penalty functions, since they lack the required smoothness.
A: A combination of two reasons: 


*

*Newton method attracts to saddle points; 

*saddle points are common in machine learning, or in fact any multivariable optimization.


Look at the function $$f=x^2-y^2$$

If you apply multivariate Newton method, you get the following.
$$\mathbf{x}_{n+1} = \mathbf{x}_n - [\mathbf{H}f(\mathbf{x}_n)]^{-1} \nabla f(\mathbf{x}_n)$$
Let's get the Hessian:
$$\mathbf{H}= \begin{bmatrix}
  \dfrac{\partial^2 f}{\partial x_1^2} & \dfrac{\partial^2 f}{\partial x_1\,\partial x_2} & \cdots & \dfrac{\partial^2 f}{\partial x_1\,\partial x_n} \\[2.2ex]
  \dfrac{\partial^2 f}{\partial x_2\,\partial x_1} & \dfrac{\partial^2 f}{\partial x_2^2} & \cdots & \dfrac{\partial^2 f}{\partial x_2\,\partial x_n} \\[2.2ex]
  \vdots & \vdots & \ddots & \vdots \\[2.2ex]
  \dfrac{\partial^2 f}{\partial x_n\,\partial x_1} & \dfrac{\partial^2 f}{\partial x_n\,\partial x_2} & \cdots & \dfrac{\partial^2 f}{\partial x_n^2}
\end{bmatrix}.$$
$$\mathbf{H}= \begin{bmatrix}
  2 & 0 \\[2.2ex]
  0 & -2
\end{bmatrix}$$
Invert it:
$$[\mathbf{H} f]^{-1}= \begin{bmatrix}
  1/2 & 0 \\[2.2ex]
  0 & -1/2
\end{bmatrix}$$
Get the gradient:
$$\nabla f=\begin{bmatrix}
  2x \\[2.2ex]
  -2y 
\end{bmatrix}$$
Get the final equation:
$$\mathbf{\begin{bmatrix}
  x \\[2.2ex]
  y 
\end{bmatrix}}_{n+1} =  \begin{bmatrix}
  x \\[2.2ex]
  y
\end{bmatrix}_n
-\begin{bmatrix}
  1/2 & 0 \\[2.2ex]
  0 & -1/2
\end{bmatrix} \begin{bmatrix}
  2x_n \\[2.2ex]
  -2y_n 
\end{bmatrix}=
\mathbf{\begin{bmatrix}
  x \\[2.2ex]
  y 
\end{bmatrix}}_n - \begin{bmatrix}
  x \\[2.2ex]
  y
\end{bmatrix}_n
=
\begin{bmatrix}
  0 \\[2.2ex]
  0
\end{bmatrix}
$$
So, you see how the Newton method led you to the saddle point at $x=0,y=0$.
In contrast, the gradient descent method will not lead to the saddle point. The gradient is zero at the saddle point, but a tiny step out would pull the optimization away as you can see from the gradient above - its gradient on y-variable is negative.
A: I recently learned this myself - the problem is the proliferation of saddle points in high-dimensional space, that Newton methods want to converge to. See this article: Identifying and attacking the saddle point problem in
high-dimensional non-convex optimization.

Indeed the ratio of the number of saddle points to local minima increases
  exponentially with the dimensionality N.
While gradient descent dynamics are repelled away from
  a saddle point to lower error by following directions of negative curvature, ...the Newton method does not treat saddle points appropriately; as
  argued below, saddle-points instead become attractive under the Newton dynamics.

A: There are many difficulties regarding the use of Newton's method for SGD, especially:

*

*it requires to know local Hessian matrix - how to estimate Hessian e.g. from noisy gradients with a sufficient precision at a reasonable cost?


*full Hessian is too costly - we rather need some its restriction, e.g. to a linear subspace (like its top eigenspace),


*it needs inverted Hessian $H^{-1}$, what is costly and very unstable for noisy estimation - can be statistically blurred around $\lambda=0$ eigenvalues which invert to infinity,


*Newton's method directly attracts to close point with zero gradient ... which is usually a saddle here. How to avoid this saddle attraction e.g. repelling them instead? For example saddle-free Newton reverses negative curvature directions, but it requires controlling signs of eigenvalues,


*it would be good to do it online - instead of performing a lot of computation in a single point, try to split it into many small steps to exploit local information about the landscape.
We can go from 1st order to 2nd order in small steps, e.g. adding update of just 3 averages to momentum method we can simultaneously MSE fit parabola in its direction for smarter choice of step size.


ps. I have prepared SGD overview lecture focused on 2nd order methods: slides: https://www.dropbox.com/s/54v8cwqyp7uvddk/SGD.pdf, video: https://youtu.be/ZSnYtPINcug
A: You asked two questions: Why don't more people use Newton's method, and why do so many
people use stochastic gradient descent? These questions have different answers, because
there are many algorithms that lessen the computational burden of Newton's method
but often work better than SGD.
First: Newton's Method takes a long time per iteration and is memory-intensive.
As jwimberley points out, Newton's Method requires computing the second derivative, $H$,
which is $O(N^2)$, where $N$ is the number of features, while computing the gradient,
$g$, is only $O(N)$. But the next step is $H^{-1} g$, which is $O(N^3)$ to compute.
So while computing the Hessian is expensive, inverting it or solving least squares is often even worse.
(If you have sparse features, the asymptotics look better, but other methods also perform
better, so sparsity doesn't make Newton relatively more appealing.)
Second, many methods, not just gradient descent, are used more often than Newton;
they are often knockoffs of Newton's method, in the sense that
they approximate a Newton step at a lower computational cost per step but take
more iterations to converge. Some examples:


*

*Because of the expense of inverting the Hessian,
``quasi-Newton" methods like BFGS approximate the inverse Hessian,
$H^{-1}$, by looking at how the gradient has changed over the last
few steps. 

*BFGS is still very memory-intensive in
high-dimensional settings because it requires storing the entire
$O(N^2)$ approximate inverse Hessian. Limited memory BFGS (L-BFGS) calculates the next
step direction as the approximate inverse Hessian times the gradient,
but it only requires storing the last several gradient updates; it
doesn't explicitly store the approximate inverse Hessian.

*When
you don't want to deal with approximating second derivatives at all,
gradient descent is appealing because it only uses only first-order
information. Gradient descent is implicitly approximating the inverse
Hessian as the learning rate times the identity matrix. I,
personally, rarely use gradient descent: L-BFGS is just as easy to
implement, since it only requires specifying the objective function
and gradient; it has a better inverse Hessian approximation than
gradient descent; and because gradient descent requires tuning the
learning rate.

*Sometimes you have a very large number of
observations (data points),  but you could learn almost as well from
a smaller number of observations. When that is the case, you can use
"batch methods", like stochastic gradient descent, that cycle through
using subsets of the observations.
A: Just some comments:

*

*First order methods have very well theoretical guarantee about convergence and avoidance of saddle points, see Backtracking GD and modifications.

*Backtracking GD can be implemented in DNN, with very good performance.

*Backtracking GD allows big learning rates, can be of the size of inverse of the size of gradient, when the gradient is small. This is very handy when you converge to a degenerate critical point.

References:
https://github.com/hank-nguyen/MBT-optimizer
https://arxiv.org/abs/2007.03618 (Here you also find a heuristic argument, that backtracking gd has correct unit, in the sense of Zeiler in his adadelta paper)
Concerning Newton’s method: with a correct modification, you can avoid saddle points, as several previous comments pointed out. Here is a rigorous proof, where we also give a simple way to proceed if the hessian is singular
https://arxiv.org/abs/2006.01512
Github link for the codes:
https://github.com/hphuongdhsp/Q-Newton-method
Remaining issues: cost of implementation and no guarantee of convergence.
Addendum:

*

*The paper of Caplan mentioned by LMB: I took a quick look. I don’t think that paper presented any algorithm which computes the Hessian in O(N). It only says that you can compute the Hessian with only N “function evaluation” - I don’t know yet what that precisely means - and the final complexity is still O(N^2). It also did some experiments and says that the usual Newton’s method works better than (L-)BFGS for those experiments.


*(related to the previous sentence). I should add this as comments to JPJ and elizabeth santorella but cannot (not enough points) so write here: since you two mentioned bfgs and l-bfgs, can you give a link to sourcodes for these for DNN (for example for datasets MNIST, CIFAR10, CIFAR100) with reported experimental results, so people can compare with first order methods (variants of gd, including backtracking gd), to have an impression of how good they are in large scale?
Tuyen Truong, UiO
A: Gradient descent maximizes a function using knowledge of its derivative. Newton's method, a root finding algorithm, maximizes a function using knowledge of its second derivative. That can be faster when the second derivative is known and easy to compute (the Newton-Raphson algorithm is used in logistic regression). However, the analytic expression for the second derivative is often complicated or intractable, requiring a lot of computation. Numerical methods for computing the second derivative also require a lot of computation -- if $N$ values are required to compute the first derivative, $N^2$ are required for the second derivative. 
A: Gradient descent direction's cheaper to calculate, and performing a line search in that direction is a more reliable, steady source of progress toward an optimum.  In short, gradient descent's relatively reliable.
Newton's method is relatively expensive in that you need to calculate the Hessian on the first iteration.  Then, on each subsequent iteration, you can either fully recalculate the Hessian (as in Newton's method) or merely "update" the prior iteration's Hessian (in quasi-Newton methods) which is cheaper but less robust.
In the extreme case of a very well-behaved function, especially a perfectly quadratic function, Newton's method is the clear winner.  If it's perfectly quadratic, Newton's method will converge in a single iteration.
In the opposite extreme case of a very poorly behaved function, gradient descent will tend to win out.  It'll pick a search direction, search down that direction, and ultimately take a small-but-productive step.  By contrast, Newton's method will tend to fail in these cases, especially if you try to use the quasi-Newton approximations.
In-between gradient descent and Newton's method, there're methods like Levenberg–Marquardt algorithm (LMA), though I've seen the names confused a bit.  The gist is to use more gradient-descent-informed search when things are chaotic and confusing, then switch to a more Newton-method-informed search when things are getting more linear and reliable.
