Skip to content

Condition Number of a Matrix in Machine Learning

2026-11-14

Conditioning measures how rapidly a function changes when its inputs are perturbed slightly, and a matrix with a large condition number amplifies input errors. Goodfellow, Bengio, and Courville open Section 4.2 of Deep Learning with exactly that idea: "Conditioning refers to how rapidly a function changes with respect to small changes in its inputs." They explain why it matters in computing: functions that change rapidly under small input changes "can be problematic for scientific computation because rounding errors in the inputs can result in large changes in the output."

Their example is the function f(x) = A⁻¹x. "When A ∈ Rⁿˣⁿ has an eigenvalue decomposition, its condition number is" the maximum over i and j of |λᵢ / λⱼ|, their equation 4.2. They describe it as "the ratio of the magnitude of the largest and smallest eigenvalue." Read that as a statement about symmetric matrices, and more generally normal ones, where it equals the 2-norm condition number, the largest singular value divided by the smallest; the caution below says what goes wrong otherwise. They conclude: "When this number is large, matrix inversion is particularly sensitive to error in the input. This sensitivity is an intrinsic property of the matrix itself, not the result of rounding error during matrix inversion." And they add that "Poorly conditioned matrices amplify pre-existing errors when we multiply by the true matrix inverse."

Try it by hand. Take the diagonal matrix A with entries 1 and 0.001. Its eigenvalues are 1 and 0.001, so the condition number is 1 / 0.001 = 1000. Its inverse has entries 1 and 1000. Solve A x = b, which is x = A⁻¹b, for b = (1, 0). The answer is x = (1, 0). Now suppose the input is slightly off, b = (1, 0.001), which is a change of 0.001 on a vector of size 1, a 0.1% relative change. The answer becomes x = (1, 1), a change of 1 on a vector of size 1, which is 100%. A 0.1% input change produced a 100% output change, an amplification of 1000, which equals the condition number. Now perturb the other component instead, b = (1.001, 0). The answer is x = (1.001, 0), again a 0.1% change in the input and a 0.1% change in the output. No amplification at all. So for this matrix the condition number is the worst-case amplification, and which direction the error points matters. I checked these with exact arithmetic and with NumPy's condition number function, which also returns 1000, and the matrix is invented.

The trap: thinking a good algorithm can recover accurate answers from badly conditioned data. The book's sentence says the sensitivity is a property of the matrix, not of the rounding that happens during inversion, so no inversion routine removes it; a careful algorithm only avoids adding more error on top. A caution of my own, not from the section I read: the eigenvalue ratio, the book's definition, is a reliable measure of sensitivity for symmetric matrices like the diagonal one here, and more generally for normal matrices. For other invertible matrices it can badly understate the sensitivity. The matrix with rows (1, 1000) and (0, 2) has eigenvalues 1 and 2, a ratio of 2, yet nudging b from (1, 0) to (1, 0.001) moves x from (1, 0) to (0.5, 0.0005), a 50% change from a 0.1% nudge, about 500 times. For such a matrix the number to use is the norm-based condition number, the product of the matrix norm and the inverse's norm. In the 2-norm that equals the largest singular value divided by the smallest, and here it is about 500,000.

Prof Rod's rule: check the condition number before trusting a solve, expect errors in the worst direction to grow by up to the matrix's norm-based condition number, which equals the eigenvalue ratio for symmetric matrices, and do not blame the algorithm for what the matrix does.

Goodfellow, Bengio, and Courville, Deep Learning, MIT Press, 2016, Section 4.2 Poor Conditioning, p. 80