Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for LinearSVC #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions linear_models/linearsvc_test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1.5,4.5,1
4.5,1.5,-1
40 changes: 40 additions & 0 deletions linear_models/linearsvc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package linear_models

import (
"github.com/sjwhitworth/golearn/base"
. "github.com/smartystreets/goconvey/convey"
"testing"
)

func TestLinearSVC(t *testing.T) {
Convey("Given labels, a classifier and data", t, func() {
trainingData, err := base.ParseCSVToInstances("linearsvc_train.csv", false)
So(err, ShouldBeNil)

testingData, err := base.ParseCSVToInstances("linearsvc_test.csv", false)
So(err, ShouldBeNil)

cls, err := NewLinearSVC("l2", "l2", true, 1.0, 1e-4)
So(err, ShouldBeNil)

cls.Fit(trainingData)

predictions, _ := cls.Predict(testingData)
So(predictions, ShouldNotEqual, nil)

Convey("When predicting the label for our first vector", func() {
result := base.GetClass(predictions, 0)
Convey("The result should be 1.0", func() {
So(result, ShouldEqual, "1.0")
})
})

Convey("When predicting the label for our second vector", func() {
result := base.GetClass(predictions, 1)
Convey("The result should be -1.0", func() {
So(result, ShouldEqual, "-1.0")
})
})

})
}
10 changes: 10 additions & 0 deletions linear_models/linearsvc_train.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0.0,4.0,1
0.0,6.0,1
1.0,5.0,1
2.0,4.0,1
2.0,6.0,1
4.0,0.0,-1
4.0,2.0,-1
5.0,1.0,-1
6.0,0.0,-1
6.0,2.0,-1