liveBook · Manning

Squared loss

As explained in Deep Learning with R, Third Edition

Squared error is a discrepancy measure equal to the square of the difference between a prediction and its target.

Squared loss measures prediction error by squaring the difference between each prediction and its target. Averaging these squared differences produces one loss value for training. section 3.3.2

Training a linear classifier

A linear classifier predicts two-dimensional points with prediction = matmul(input, W) + b. On 2,000 synthetic points from two classes, minimizing squared loss with batch gradient updates reduces the loss from 4.5364 to 0.0289 over 40 steps. Predictions above 0.5 separate the classes. section 3.3.2

mean_squared_error <- function(targets, predictions) {
  per_sample_losses <- tf$square(targets - predictions)  #1
  tf$reduce_mean(per_sample_losses)  #2
}

The implementation squares elementwise target-prediction differences, then averages the per-sample losses. section 3.3.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines the formula and implements averaging, then applies gradient updates without deriving the gradients mathematically.
Examples
Uses two synthetic two-dimensional point classes, R/TensorFlow code, loss logs, and a plotted decision boundary.
What it assumes
Assumes only two-dimensional inputs and scalar targets in the worked classifier example.
What you can do after
Apply via TensorFlow and R by defining squared loss and minimizing it with gradient-based parameter updates.
How it connects
Connects prediction, linear classifiers, batch training, gradients, and decision thresholds.

Also explained in

Compare how 4 books explain squared loss →

Related concepts

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