Linear algebraLesson 2 of 6
Multiply matching entries, then add
Weighted sums and dot products
Consider a candidate prediction rule for our example quiz records: award 2 predicted points per study hour and 1 per completed set. For record 2, with 2 hours and 1 set, it gives
We chose those weights to inspect the calculation. We have not learned them from data, and they are not claims about how studying causes performance.
One number from two lists
Section titled “One number from two lists”Write the feature vector as and the weights as . Multiply each feature by its corresponding weight, then add:
This operation is the dot product. Its result is a scalar, a single number. With features, the rule is
Read as “add one term for each feature, starting at 1 and ending at .” Both vectors must have the same number of entries, with corresponding entries representing the same features. Weight units make the additions meaningful: points per hour times hours gives points, as does points per set times sets.
The same dot product also appears as . The transpose makes a row so that a row times a column produces one number. These are two notations for the same calculation.
Length and perpendicularity
Section titled “Length and perpendicularity”Dot products are useful beyond prediction. A vector dotted with itself gives the sum of its squared entries:
Its Euclidean length, written , is . In an ordinary coordinate plot, this follows from the Pythagorean theorem. With features measured in different units, the resulting length depends on the chosen scales; do not mistake it for an automatically meaningful measure of similarity.
Now use . Then . The two directions are orthogonal, meaning perpendicular in Euclidean geometry. The positive and negative contributions cancel.
For nonzero vectors, dividing the dot product by both lengths gives the cosine of their angle. A raw dot product itself also depends on length: doubling either vector doubles the product. It is therefore not a pure measure of direction.
Try it
Section titled “Try it”Keep , but change the weights to . What prediction do you obtain? What does the negative weight do?
Work through the answer
. The set feature contributes point to this candidate rule. Different weights can agree on one record; later we will compare their predictions across several records.
For another geometric explanation, see Georgia Tech’s chapter on dot products.