-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluation.go
36 lines (32 loc) · 1.04 KB
/
evaluation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package algorithms
import (
"math"
"fmt"
"github.com/rom1mouret/ml-essentials/dataframe"
)
// MSE returns the mean-squared-error between two views on float vectors.
// mse = MEAN((yPred - yTrue)^2)
func MSE(yPred dataframe.FloatAccess, yTrue dataframe.FloatAccess) float64 {
if yPred.Size() != yTrue.Size() {
panic(fmt.Sprintf("size(yPred)=%d != size(yTrue)=%d", yPred.Size(), yTrue.Size()))
}
result := 0.0
for i := 0; i < yPred.Size(); i++ {
diff := yPred.Get(i) - yTrue.Get(i)
result += diff * diff
}
return result / float64(yPred.Size())
}
// MAE returns the mean-absolute-error between two views on float vectors.
// mae = MEAN((|yPred - yTrue|)
func MAE(yPred dataframe.FloatAccess, yTrue dataframe.FloatAccess) float64 {
if yPred.Size() != yTrue.Size() {
panic(fmt.Sprintf("size(yPred)=%d != size(yTrue)=%d", yPred.Size(), yTrue.Size()))
}
result := 0.0
for i := 0; i < yPred.Size(); i++ {
result += math.Abs(yPred.Get(i) - yTrue.Get(i))
}
return result / float64(yPred.Size())
}
// TODO: Cross Entropy etc.