This repository was archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathvalidation_test.go
50 lines (43 loc) · 1.5 KB
/
validation_test.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2015 The golinear Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
package golinear
import "testing"
func tenInstanceProblem(t *testing.T) *Problem {
problem := NewProblem()
problem.Add(TrainingInstance{0,
FromDenseVector([]float64{1, 1, 1, 0, 0})})
problem.Add(TrainingInstance{0,
FromDenseVector([]float64{1, 1, 1, 0, 0})})
problem.Add(TrainingInstance{0,
FromDenseVector([]float64{1, 1, 0, 0, 0})})
problem.Add(TrainingInstance{0,
FromDenseVector([]float64{1, 1, 0, 0, 0})})
problem.Add(TrainingInstance{0,
FromDenseVector([]float64{1, 1, 0, 0, 0})})
problem.Add(TrainingInstance{1,
FromDenseVector([]float64{0, 0, 1, 1, 1})})
problem.Add(TrainingInstance{1,
FromDenseVector([]float64{0, 0, 1, 1, 1})})
problem.Add(TrainingInstance{1,
FromDenseVector([]float64{0, 0, 0, 1, 1})})
problem.Add(TrainingInstance{1,
FromDenseVector([]float64{0, 0, 0, 1, 1})})
problem.Add(TrainingInstance{1,
FromDenseVector([]float64{0, 0, 0, 1, 1})})
return problem
}
func TestCrossValidation(t *testing.T) {
problem := tenInstanceProblem(t)
param := DefaultParameters()
results, err := CrossValidation(problem, param, 10)
if err != nil {
t.Errorf("Could not train model: %s", err.Error())
}
correctResults := []float64{0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
for idx, class := range correctResults {
if results[idx] != class {
t.Errorf("class(%d) = %f, want class(%d) = %f", idx, results[idx], idx, class)
}
}
}