1 people like it.

Average Square Error

In statistics, one of the standard ways to calculate an estimate/estimation quality, to be able to compare how good are different estimates.

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
let inline averageSquareError estimated actual = 
    Array.zip estimated actual
    |> Array.averageBy (fun (w,o) -> pown (o - w) 2)

//let estimated = [|1.0; 2.0; 3.0; 4.0; 5.0|]
//let actual    = [|1.1; 2.2; 2.8; 4.0; 5.1|]

//let err = averageSquareError actual estimated
//val err : float = 0.02
val averageSquareError : estimated:'a [] -> actual:'b [] -> 'c (requires member ( - ) and member get_Zero and member DivideByInt and member ( + ) and member get_One and member ( * ) and member ( / ))

Full name: Script.averageSquareError
val estimated : 'a [] (requires member ( - ) and member get_Zero and member DivideByInt and member ( + ) and member get_One and member ( * ) and member ( / ))
val actual : 'b [] (requires member ( - ) and member get_Zero and member DivideByInt and member ( + ) and member get_One and member ( * ) and member ( / ))
module Array

from Microsoft.FSharp.Collections
val zip : array1:'T1 [] -> array2:'T2 [] -> ('T1 * 'T2) []

Full name: Microsoft.FSharp.Collections.Array.zip
val averageBy : projection:('T -> 'U) -> array:'T [] -> 'U (requires member ( + ) and member DivideByInt and member get_Zero)

Full name: Microsoft.FSharp.Collections.Array.averageBy
val w : 'a (requires member ( - ) and member get_Zero and member DivideByInt and member ( + ) and member get_One and member ( * ) and member ( / ))
val o : 'b (requires member ( - ) and member get_Zero and member DivideByInt and member ( + ) and member get_One and member ( * ) and member ( / ))
val pown : x:'T -> n:int -> 'T (requires member get_One and member ( * ) and member ( / ))

Full name: Microsoft.FSharp.Core.Operators.pown
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/7TC
Posted:7 years ago
Author:Tuomas Hietanen
Tags: error , statistics