mirror of
https://github.com/sjwhitworth/golearn.git
synced 2025-04-26 13:49:14 +08:00
evaluation: merge from v2-instances
This commit is contained in:
parent
c2d040af30
commit
3fea8395a9
@ -11,19 +11,22 @@ type ConfusionMatrix map[string]map[string]int
|
||||
|
||||
// GetConfusionMatrix builds a ConfusionMatrix from a set of reference (`ref')
|
||||
// and generate (`gen') Instances.
|
||||
func GetConfusionMatrix(ref *base.Instances, gen *base.Instances) map[string]map[string]int {
|
||||
func GetConfusionMatrix(ref base.FixedDataGrid, gen base.FixedDataGrid) map[string]map[string]int {
|
||||
|
||||
if ref.Rows != gen.Rows {
|
||||
_, refRows := ref.Size()
|
||||
_, genRows := gen.Size()
|
||||
|
||||
if refRows != genRows {
|
||||
panic("Row counts should match")
|
||||
}
|
||||
|
||||
ret := make(map[string]map[string]int)
|
||||
|
||||
for i := 0; i < ref.Rows; i++ {
|
||||
referenceClass := ref.GetClass(i)
|
||||
predictedClass := gen.GetClass(i)
|
||||
for i := 0; i < int(refRows); i++ {
|
||||
referenceClass := base.GetClass(ref, i)
|
||||
predictedClass := base.GetClass(gen, i)
|
||||
if _, ok := ret[referenceClass]; ok {
|
||||
ret[referenceClass][predictedClass]++
|
||||
ret[referenceClass][predictedClass] += 1
|
||||
} else {
|
||||
ret[referenceClass] = make(map[string]int)
|
||||
ret[referenceClass][predictedClass] = 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user