1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-04-28 13:48:56 +08:00
golearn/linear_models/linear_models_test.go

40 lines
972 B
Go
Raw Normal View History

2014-07-02 15:48:35 +01:00
package linear_models
import (
"testing"
2014-07-02 15:48:35 +01:00
"github.com/sjwhitworth/golearn/base"
. "github.com/smartystreets/goconvey/convey"
)
func TestLogisticRegression(t *testing.T) {
Convey("Given labels, a classifier and data", t, func() {
2014-08-02 16:22:15 +01:00
// Load data
2014-07-02 15:48:35 +01:00
X, err := base.ParseCSVToInstances("train.csv", false)
So(err, ShouldEqual, nil)
Y, err := base.ParseCSVToInstances("test.csv", false)
So(err, ShouldEqual, nil)
2014-08-02 16:22:15 +01:00
// Setup the problem
lr, err := NewLogisticRegression("l2", 1.0, 1e-6)
So(err, ShouldBeNil)
2014-07-02 15:48:35 +01:00
lr.Fit(X)
Convey("When predicting the label of first vector", func() {
Z, err := lr.Predict(Y)
So(err, ShouldEqual, nil)
Convey("The result should be 1", func() {
So(Z.RowString(0), ShouldEqual, "1")
})
})
Convey("When predicting the label of second vector", func() {
Z, err := lr.Predict(Y)
So(err, ShouldEqual, nil)
Convey("The result should be -1", func() {
So(Z.RowString(1), ShouldEqual, "0")
})
})
})
}