Continue with math for machine learning, this article will give a quick note on definition of linear dependence and demonstration with python.
Linear Dependence
In the theory of vector spaces, a set of vectors is said to be linearly dependent if at least one of the vectors in the set can be defined as a linear combination of the others; if no vector in the set can be written in this way, then the vectors are said to be linearly independent.
Definition: The vectors in a subset of a vector space
V
are said to be ”linearly dependent”, if there exist scalars , not all zero, such that
, where
denotes the zero vector.
The above vectors are not linear independent as
System of linear equation
Linear dependence has a strong relation to solution of linear equations. Since it is all about systems of linear equations, let’s start again with the set of equations:
We know A
and b
as constant terms and need to find x
.
Matrix equation
The system is equivalent to a matrix equation of the form
Where A
is a m x n
matrix of coefficients, x
and b
is column vectors. The equation corresponds to:
Number of solutions
Three cases can represent the number of solutions of the system of equations Ax=b.
- No solution
- Exactly 1 solution
- An infinite number of solutions
It is because we are dealing with linear systems: 2 lines can’t cross more than once as illustrated below

Solve systems of equations with numpy
.
To find x:
So the solution exists if A is invertible ( exists). To solve the standard linear system, we can use
numpy.linalg.solve(A, b)
.
Example 1: Solve the system of equations (no solution)
a = np.array([[-3,-1], [-3, -1]])
b = np.array([9,7])
x = np.linalg.solve(a, b)
print(x)
#LinAlgError: Singular matrix
Example 2: Solve the system of equations (one solution)
a = np.array([[3,1,1], [1,2,3], [2, 0.5,4]])
b = np.array([9,8,7])
x = np.linalg.solve(a, b)
print(x)
#[2.08333333 2.33333333 0.41666667]
Check that the solution is correct:
np.allclose(np.dot(a, x), b)
#True
Example 3: Solve the system of equations (infinite solutions)
import numpy as np
a = np.array([[3,1], [6,2]])
b = np.array([9,18])
x = np.linalg.solve(a, b)
print(x)
#LinAlgError: Singular matrix
This system has infinite solutions and matrix a is not invertible. Its rows are linear dependent.
Check linear dependency
Use Eigenvalue: If one eigenvalue of the matrix is zero, its corresponding eigenvector is linearly dependent. The eigenvalues are not necessarily ordered. A method would be:
matrix = np.array(
[
[0, 1 ,0 ,0],
[0, 0, 1, 0],
[0, 1, 1, 0],
[1, 0, 0, 1]
])
w, v = np.linalg.eig(matrix.T)
# The linearly dependent row vectors
print matrix[w == 0,:]
w: The eigenvalues, each repeated according to its multiplicity.
v: The normalized (unit “length”) eigenvectors, such that the column v[:,i]
is the eigenvector corresponding to the eigenvalue w[i]
References:
[1] Marc P.D, A. Aldo, Cheng S.O, Math for machine learning, url: https://mml-book.github.io/book/mml-book.pdf
[2] Deep learning book series, url https://hadrienj.github.io/posts/Deep-Learning-Book-Series-2.4-Linear-Dependence-and-Span/
[3] Wikipedia, https://en.wikipedia.org/wiki/System_of_linear_equations