Vectors
Log in to access the full course.
What a vector is
A vector is an ordered list of numbers. In machine learning, vectors are the fundamental way to represent data points, features, weights, and predictions.
A vector in has components and lives in -dimensional space. A training example with 5 features is a vector in .
Two interpretations
As a point: a location in -dimensional space. The vector is the point 3 units right and 2 units up from the origin.
As a direction and magnitude: an arrow from the origin to that point, with a direction and a length. This interpretation is more useful for operations like addition and scaling.
Both interpretations coexist and are useful in different contexts.
Vector operations
Addition: add component-wise. Adding two vectors combines their displacements — geometrically, you follow one arrow then the other.
Scalar multiplication: multiply every component by a number . Scales the length of the vector without changing its direction (unless , which flips direction).
Magnitude (norm)
The magnitude or L2 norm of a vector is its length:
This is the Euclidean distance from the origin to the point .
A unit vector has magnitude 1. Dividing any non-zero vector by its magnitude normalizes it: .
Why vectors matter in ML
In ML, everything is a vector:
- A training example with features is a vector .
- The weights of a linear model are a vector .
- A prediction is a vector (or scalar — a 1D vector).
- A word embedding maps a word to a vector in, say, .
The entire computation of a linear model — predicting — is a vector operation. Training updates the weight vector. Regularization penalizes its magnitude.
Linear combinations and span
A linear combination of vectors is any sum for scalars . The set of all possible linear combinations is the span of those vectors.
If you can reach any point in by linear combinations of a set of vectors, those vectors span the full space. If they are redundant (one is a multiple of another), they only span a lower-dimensional subspace. This concept underlies matrix rank and linear dependence, covered in the rank lesson.