forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeanSquareError.js
More file actions
Latest commit
21 lines (15 loc) · 526 Bytes
/
Copy pathMeanSquareError.js
File metadata and controls
21 lines (15 loc) · 526 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Wikipedia: https://en.wikipedia.org/wiki/Mean_squared_error
constmeanSquaredError=(predicted,expected)=>{
if(!Array.isArray(predicted)||!Array.isArray(expected)){
thrownewTypeError('Argument must be an Array')
}
if(predicted.length!==expected.length){
thrownewTypeError('The two lists must be of equal length')
}
leterr=0
for(leti=0;i<expected.length;i++){
err+=(expected[i]-predicted[i])**2
}
returnerr/expected.length
}
export{meanSquaredError}