Last active
October 19, 2020 20:42
-
-
Save jwilber/a431f6536faa42f9b5b2d12e068515a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// calculate MSE for two equal-dimension arrays | |
const meanSquaredError = (actual, pred) => { | |
// helper funcs | |
const sqr = a => a * a; | |
const add = (a, b) => a + b; | |
const difference = (a, b) => a.map((x, i) => x - b[i]); | |
// calculate MSE | |
const squaredError = difference(actual, pred).map(sqr); | |
const sumSquaredError = squaredError.reduce(add, 0); | |
const mse = sumSquaredError / actual.length; | |
return mse | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment