Regression predicts a continuous value, such as a house price, rather than choosing a class label. A linear model starts with a simple prediction rule: multiply each input by a learned weight, add the results, then add a bias. For two inputs, that is prediction = w1 × x1 + w2 × x2 + b. Training adjusts the weights and bias so predictions better match known targets. section 4.3 section 3.3.2
model <- function(inputs, W, b) {
tf$matmul(inputs, W) + b
}
This R/TensorFlow function expresses the prediction rule as matrix multiplication plus a bias: tf$matmul(inputs, W) + b. The same computation can produce a continuous score or serve as the starting point for a classifier. section 3.3.2
Strictly, matrix multiplication is a linear transform; adding b makes the computation an affine transform. Rotation and scaling are geometric examples of linear transforms. Stacking layers that perform only affine transforms still yields an affine transform, so additional layers need activation functions to model nonlinear relationships. section 2.3.5
Fit and inspect a simple model
For two synthetic clusters of points, initialize W and b, calculate predictions, measure mean squared error against the targets, and repeatedly update W and b using gradients. Plotting the resulting predictions shows a straight decision boundary when scores are split at 0.5. This is a linear classifier trained with squared error—not an example of predicting a continuous regression target. section 3.3.2 section 3.4.2
For continuous targets, mean squared error (MSE) is a common training loss, while mean absolute error (MAE) gives an interpretable evaluation measure; classification accuracy does not apply. A scalar regression model commonly ends with one unit and no activation, leaving its output range unconstrained. That does not make the whole model linear: the house-price example has two earlier layers with relu activations. section 4.3.3 section 4.3.6
Listing 4.24 Model definition
get_model <- function() { #1
model <- keras_model_sequential() |>
layer_dense(64, activation = "relu") |>
layer_dense(64, activation = "relu") |>
layer_dense(1)
model |> compile(
optimizer = "adam",
loss = "mean_squared_error",
metrics = "mean_absolute_error"
)
model
}
Compare the final layer_dense(1) with the two preceding relu layers. The final prediction is unconstrained, but the complete house-price model is not a linear regression model. section 4.3.3





















