liveBook · Manning

Linear regression

As explained in Deep Learning with PyTorch, Second Edition

A mathematical mapping that combines inputs linearly, used here as a component of neural network layers before activation.

Linear regression predicts a continuous value by scaling an input and adding an offset. It is a useful first model when two measurements might be related by a line. section 5.2.1 section 5.2.4

Reading an unfamiliar thermometer

Suppose a thermometer has no units, but you have several readings paired with Celsius temperatures. Try `t_c = w * t_u + b`: `t_u` is the unfamiliar reading, `w` is the weight that scales it, and `b` is the bias added afterward. Fitting the model means finding values of `w` and `b` that bring its predictions close to the measured temperatures. section 5.2.1 section 5.2.4

A loss function measures prediction error. Training repeatedly updates the parameters to lower that loss. In PyTorch, gradients computed through autograd can guide those updates; the same forward-pass, loss, backward-pass, and update pattern also applies to neural networks. section 5.2.4 section 5.8

A line cannot change slope at different input values. Neural networks extend the scaling-and-offset operation with nonlinear activation functions, then compose many such units to fit more complicated relationships. Extra flexibility is not always better: on a small, noisy temperature dataset, even a tiny network can chase individual measurements rather than fit a simple line. section 6.1.3 section 6.3.3

Figure 6.6 Composing multiple linear units and tanh activation functions to produce nonlinear outputs
figure

See how composing linear units with tanh activations produces outputs more varied than a single line. section 6.1.6

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Works through weight, bias, loss, and parameter updates, then contrasts a line with nonlinear networks rather than developing a general regression theory.
Examples
Uses paired thermometer and Celsius readings, then compares a neural network’s predictions with a line on noisy temperature data.
What it assumes
Starts with paired input and target measurements and defines weight, bias, and loss before moving to neural networks.
What you can do after
Build it from scratch by fitting a weight and bias to paired temperatures while minimizing prediction error in PyTorch.
How it connects
Connects regression to loss functions, stochastic gradient descent, neural networks, and activation functions.

Also explained in

Compare how 22 books explain linear regression →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.