Mean squared error
The one number a model is trying to push down while it learns.
When a model guesses numbers, we need one score for how wrong it is. Mean squared error takes each miss, squares it so big misses count extra, then averages.
Write mse(predicted, actual): two arrays of numbers with the same length. Return the average of (predicted[i] - actual[i]) squared. If the arrays are empty, return 0.
Example: mse([1, 2], [1, 4]) returns 2, because the misses are 0 and 2, the squares are 0 and 4, and their average is 2.
Tests you can see
mse([1,2], [1,4])2mse([3,5,7], [3,5,7])0mse([2,0,4], [1,1,1])3.6666666666666665
More tests are hidden. The server runs them all before a time counts.
The idea behind this, in a two-minute live pageRun your code to see the tests.
javascriptmse()
Tab indents · Cmd/Ctrl+Enter runs