Vectors as Data Points: The Geometry Behind a Feature Table
See how each row of a feature table becomes a point in space, and what distance, direction and flat boundaries mean for your model.
Key takeaways
- A row is a point with d coordinates, and the whole feature table is an n by d matrix with examples as rows.
- Distance between rows measures similarity only as well as the columns and their units allow.
- Rescaling one column can change which example is another's nearest neighbor.
- A linear model scores a point by how far it sits on one side of a flat surface.
- Categories, text and missing values need an explicit encoding before the geometry means anything.
Each row of a numeric feature table can be read as a vector, an ordered list of numbers, and each vector can be read as a point in a space with one axis per column. A table with n rows and d numeric columns is a cloud of n points in d dimensions.
That change of view is what lets a model talk about similar examples, typical examples and boundaries between classes. It also exposes a catch: the geometry depends on choices you made while building the table, including units, encodings and which columns you kept.
From a table to points
Take three apartments described by floor area in square meters and number of bedrooms.
| Apartment | Area (m²) | Bedrooms |
|---|---|---|
| A | 70 | 2 |
| B | 75 | 4 |
| C | 95 | 2 |
Apartment A becomes the vector (70, 2), a point 70 units along the first axis and 2 along the second. With two columns you can draw it on paper. With 50 columns you cannot, but every formula you use in two dimensions still works.
The table as a whole is usually called X. Its shape is (n, d): n rows of examples and d columns of features. The target, such as monthly rent, sits apart in a vector y of length n. Keeping y out of X matters, because anything in X is treated as information available at prediction time. The vocabulary is covered further in features, labels and examples.
Columns are vectors too
You can slice the same matrix the other way. Each column is a vector with n entries, one per example. This view answers questions about features instead of examples.
Two columns that point in nearly the same direction, once their means are subtracted, are strongly correlated. A column that can be built by adding multiples of other columns carries no new linear information. The number of columns that cannot be rebuilt this way is the rank of the matrix.
Suppose you add a column "area in square feet" to the apartment table. It is the area column multiplied by a constant, so the rank does not rise. The points still lie on a flat sheet inside the larger space, and a linear model cannot decide how to split credit between the two copies.
Distance as a measure of similarity
The most familiar distance is Euclidean distance, the straight-line length between two points. Subtract coordinate by coordinate, square, add and take the square root.
d(A, B) = √((75 − 70)² + (4 − 2)²) = √(25 + 4) = √29 ≈ 5.39
d(A, C) = √((95 − 70)² + (2 − 2)²) = √(625 + 0) = √625 = 25 By this measure B is far closer to A than C is. Most of the number, though, comes from area simply because area is recorded in larger numbers. Two extra bedrooms barely register.
Euclidean distance is one choice among several. You might add up absolute differences instead, or compare directions with cosine similarity. Each choice encodes an opinion about what "alike" means.
Units decide the shape of the cloud
A common fix is to divide each column by its spread. Suppose that across your training data the standard deviation of area is 20 m² and that of bedrooms is 1. Measure each difference in standard deviations.
d(A, B) = √((5/20)² + (2/1)²) = √(0.0625 + 4) ≈ 2.02
d(A, C) = √((25/20)² + (0/1)²) = √(1.5625) = 1.25 The nearest neighbor of A has changed from B to C. Neither answer is correct by nature. The second one says that two bedrooms is a bigger difference than 25 square meters, relative to how much each usually varies.
The code below reproduces both results. The array has shape (3, 2), with rows as apartments.
import numpy as np
X = np.array([[70.0, 2], [75, 4], [95, 2]]) # shape (n=3, d=2)
scale = np.array([20.0, 1.0]) # training-set spreads
raw = np.linalg.norm(X - X[0], axis=1)
scaled = np.linalg.norm((X - X[0]) / scale, axis=1)
print(raw.round(2)) # distances from A: 0, 5.39, 25
print(scaled.round(2)) # distances from A: 0, 2.02, 1.25 Compute the means and spreads on the training rows only, then reuse them for validation and test rows. Scaling choices affect distance-based and gradient-based methods much more than tree-based ones, which split one column at a time.
Centers, differences and directions
Once rows are points, you can do arithmetic with them. The centroid is the column-by-column average. For the three apartments it is (80, 8/3), roughly 80 m² and 2.67 bedrooms. No actual apartment has that bedroom count, a reminder that an average point need not be a possible example.
Subtracting the centroid from every row, called centering, moves the cloud so that its middle sits at the origin. The shape does not change. Many methods, including principal component analysis, start here.
The difference between two points is itself a vector with a direction. B − A = (5, 2) says "5 more square meters and 2 more bedrooms". In learned vector representations, some directions line up roughly with recognizable properties, though you should test that rather than assume it.
What a linear model sees
A linear model computes a score ŷ = w · x + b, where w holds one weight per feature and b is a constant. The set of points where the score equals zero is a hyperplane: a line in two dimensions, a plane in three and the flat equivalent beyond that.
Say w = (0.1, 1) and b = −10. The scores are −1 for A, 1.5 for B and 1.5 for C. A falls on one side of the line, B and C on the other.
The vector w is perpendicular to the boundary and points toward higher scores. Dividing the score by the length of w, here √1.01 ≈ 1.005, gives the signed distance from the point to the boundary. That is about −1.0 for A and 1.5 for B, measured in the raw coordinates.
This picture underlies logistic regression and each unit of a neural network before its nonlinearity. Neural networks gain power by bending the space through many layers so that a final flat boundary can separate the classes.
Turning other columns into coordinates
Not every column arrives as a meaningful number. The encoding you pick creates the geometry.
| Column type | Common encoding | Geometric effect |
|---|---|---|
| Unordered category | One-hot columns of 0s and 1s | All distinct categories sit equally far apart |
| Ordered grade | Integers 1, 2, 3 | Assumes equal spacing between grades |
| Hour of day | Sine and cosine pair | Late evening sits next to early morning |
| Short text | Word counts or a learned vector | Closeness reflects shared words or learned meaning |
| Missing value | Filled value plus an indicator | The indicator separates filled rows from observed ones |
Coding three cities as 1, 2 and 3 tells a distance-based or linear model that the third is twice as far from the first as the second is. If that is not true, use one-hot columns or learned category vectors.
For the hour of day, map h to (sin(2πh/24), cos(2πh/24)). Hours 23 and 0 then land close together on a circle, while the raw integers would put them 23 apart.
Many rows at once
The matrix view lets you score every example in one operation. With X of shape (n, d) and w of shape (d,), the product Xw has shape (n,), one score per row. In NumPy that is X @ w + b.
You can read the same product two ways. Row by row, it is n separate dot products. Column by column, it is a weighted sum of the feature columns, with the weights taken from w. The second reading explains a limit of linear models: whatever weights you choose, the vector of predictions (before adding b) can only be a combination of the columns you supplied. If the pattern in the target cannot be built from them, you need new features or a model that bends.
Where the picture misleads
Your intuition comes from two and three dimensions. With many noisy columns, pairwise distances tend to bunch together and neighbors lose meaning, a problem known as the curse of dimensionality.
Duplicated or highly correlated columns count the same fact several times in a distance. Outliers can stretch an axis so that ordinary points look identical. A leaked column, one that contains information about the target, can make classes look beautifully separated in training and fail in use.
Before trusting any method that depends on geometry, run a quick inspection:
- Print the five nearest neighbors of a few rows and ask whether you would call them similar.
- Check each column's range and spread for surprises such as placeholder values like −999.
- Look for columns that are copies or sums of others.
- Confirm that every column would exist at the moment you need a prediction.
Common questions
Is a vector a point or an arrow?
Both readings are useful. Use "point" when you mean an example's location, and "arrow" when you mean a difference or a direction such as a weight vector.
Do all models care about this geometry?
No. Nearest neighbor methods and kernel methods depend on it directly. Linear models depend on it through their boundaries and penalties. Decision trees mostly ignore scale because a threshold on one column splits the rows the same way after rescaling.
What is the shape of a single example in code?
In many libraries a model expects a two-dimensional array even for one row, with shape (1, d). A flat array of shape (d,) is a different object, so check the documentation of the function you call.