Welcome. This course begins by rebuilding the mathematical and statistical foundations that support reliable predictive modeling and, later, causal inference. In this first module, the focus is on the compact linear-algebra operations behind models such as linear regression, logistic regression, neural networks, and rule-based lead scores.
Today’s goal is precise: compute a linear prediction as a weighted sum using a vector dot product. This is a small operation with a large role: whenever a model combines several input features into one score, a dot product is usually close by.
From a rule score to a linear prediction
Suppose a B2B SaaS workspace is being scored on day 7 of its trial. Imagine we use three numeric features:
- : number of active days during the first week
- : number of teammates invited
- : number of key actions completed
A simple scoring rule might assign different importance to each feature:
The values , , and are weights. They quantify how much each feature contributes to the score, under this particular model. The final is the intercept (also called a bias or offset): it is the score assigned when every feature is zero.
For a workspace with
the calculation is
This is a weighted sum: multiply each input by its matching weight, then add the results.
It is important not to overinterpret this score yet. It is not automatically a probability, nor does it establish that inviting teammates causes conversion. At this stage, it is simply a numerical prediction or ranking score produced by a specified rule.
Vectors and the dot product
When there are only two or three features, writing a weighted sum in full is manageable. Production datasets may have dozens, hundreds, or thousands of features, so we need compact notation.
Put the features into a column vector:
and the corresponding weights into another vector:
The dot product of two equal-length vectors is formed by multiplying corresponding entries and summing:
where is the number of features. In our example,
Adding the intercept gives the prediction:
The “hat” in means an estimated or predicted value. The key point is that the dot product produces one scalar number, not another vector.
The transpose symbol, , turns a column vector into a row vector:
Thus,
The transpose makes the dimensions compatible: a row with three entries multiplies a column with three entries and yields a single value. Dimension checking will become central in the next lesson; for now, remember the practical rule:
A dot product requires two vectors with one entry for the same set of features, in the same order.

The feature order is not a cosmetic detail. If the first weight is meant for active days but is accidentally paired with the number of invited teammates, the code will still run while the model becomes semantically wrong.
Dot products and duality | Chapter 9, Essence of linear algebra
Watch “Dot products and duality” by 3Blue1Brown for a concise visual account of the coordinate calculation and an optional geometric intuition.
In the opening portion, watch the calculation. Focus first on the required equal dimensions and the pairing of corresponding coordinates. Then notice the geometric interpretation: aligned vectors have a positive dot product, perpendicular vectors have a dot product of zero, and opposed directions tend to produce a negative result. For predictive models, the coordinate calculation is the essential part; the geometry becomes more useful later in linear algebra.
The same operation in model notation
The general form of a linear prediction is
or, more compactly,
Each term is that feature’s signed contribution to the prediction.
For the trial-conversion example:
| Feature | Value | Weight | Contribution |
|---|---|---|---|
| Active days | |||
| Teammates invited | |||
| Key actions | |||
| Weighted sum | |||
| Intercept | |||
| Prediction |
A positive weight means that, holding the other feature values fixed, a larger feature value raises the score. A negative weight lowers it. For example, a feature measuring unresolved errors might plausibly receive a negative weight.
However, the magnitude of a weight cannot be compared naively when features use different scales. A weight of per active day and a weight of per event may both matter substantially if event counts range into the hundreds. Later, preprocessing and coefficient interpretation will address this carefully.
The intercept has a specific mathematical role: it permits the prediction line, plane, or higher-dimensional surface to shift away from zero. Without it, the model would be forced to predict whenever all features equal . That constraint is often unjustified.
Strictly speaking, is linear, while is an affine function because of the added offset. In machine-learning practice, the full form is still routinely called a “linear model.”
Read the opening model section of “Linear Regression” from Dive into Deep Learning. It connects the weighted-sum calculation to standard machine-learning notation and introduces the meaning of the intercept.
In Section 3.1.1.1, “Model,” read the model explanation. Follow the transition from the two-feature price example to the general expression with d features, then focus on why the authors write a one-row prediction as \hat{y} = \mathbf{w}^{\mathsf{T}}\mathbf{x} + b. The final paragraph briefly introduces the dataset-wide design matrix; recognize it as a preview, rather than trying to master it yet.
Dot product versus elementwise multiplication
A common source of bugs is confusing a dot product with elementwise multiplication.
For the vectors
elementwise multiplication gives another vector:
The symbol is often used to distinguish elementwise multiplication from matrix multiplication. The dot product is the sum of those entries:
So the computational recipe is:
- Pair each feature with its matching weight.
- Multiply each pair.
- Sum all products.
- Add the intercept, if the model has one.
This distinction is directly visible in NumPy:
import numpy as np
x = np.array([4.0, 3.0, 2.0])
w = np.array([2.0, 0.8, 1.5])
b = 5.0
contributions = w * x
weighted_sum = np.dot(w, x)
prediction = weighted_sum + b
print(contributions) # [8. 2.4 3. ]
print(weighted_sum) # 13.4
print(prediction) # 18.4
The expression w * x performs elementwise multiplication. In contrast, np.dot(w, x) reduces the paired products to one scalar.
For one-dimensional NumPy arrays, these are equivalent:
np.dot(w, x)
w @ x
The @ operator is generally pleasant to read in model code:
prediction = w @ x + b
For actual modeling workflows, avoid relying solely on raw positional arrays. Preserve feature names during preparation, and make the feature-order contract explicit. A model coefficient is meaningful only relative to the feature column it multiplies.
The Dot Product — Topic 14 of Machine Learning Foundations
Watch the short computational segment of “The Dot Product — Topic 14 of Machine Learning Foundations” by Jon Krohn. It reinforces the reduction from elementwise products to one scalar and shows the corresponding NumPy operation.
Watch the arithmetic for the multiply-then-sum procedure. Then watch the NumPy example, focusing on the fact that np.dot returns the scalar result rather than the intermediate vector of contributions.
A useful interpretation: a model is a scoring function
The expression
takes a feature vector as input and returns one number. It is therefore a scoring function.
For a fixed weight vector :
- changing a feature changes its contribution;
- changing a weight changes how the model responds to that feature;
- changing shifts every prediction by the same amount.
Consider two trial workspaces:
Using the same weights and intercept, their difference in score is
The intercept cancels:
Only the key-actions feature changed, increasing by , so the score increases by . This is the basic local logic behind interpreting a linear model’s coefficients. Later, when logistic regression is introduced, the output will be transformed into a probability, but the central weighted-sum calculation remains.
For now, build the habit of reading every linear prediction in two layers:
That habit will help when reading scikit-learn model parameters, inspecting a legacy lead-score formula, and eventually understanding the linear layers inside neural networks.
Key takeaways
A dot product is the operation that turns two equal-length vectors into one number by multiplying matching entries and summing the products:
A linear prediction adds an intercept:
In predictive modeling, contains feature values, contains learned or hand-specified weights, and the result is a score or prediction. Keep elementwise multiplication separate from the dot product: the former returns all feature contributions, while the latter sums them into one scalar.
Next, the same idea will scale from one workspace to many: you will use matrix multiplication and dimension checks to compute a whole vector of predictions from a dataset.