1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-04-28 13:48:56 +08:00
golearn/linear_models/logistic_test.go
Richard Townsend 5ceb4e7111 linear_models: fix cgo issues, upgrade to liblinear 2.14
Requires an additional step to install:
 - cd /tmp &&
 - wget https://github.com/cjlin1/liblinear/archive/v241.tar.gz
 - tar xvf v241.tar.gz
 - cd liblinear-241
 - make lib
 - sudo install -vm644 linear.h /usr/include
 - sudo install -vm755 liblinear.so.4 /usr/lib
 - sudo ln -sfv liblinear.so.4 /usr/lib/liblinear.so
2020-09-06 10:01:24 +01:00

40 lines
1.0 KiB
Go

package linear_models
import (
"testing"
"github.com/sjwhitworth/golearn/base"
. "github.com/smartystreets/goconvey/convey"
)
func TestLogistic(t *testing.T) {
Convey("Doing a logistic test", t, func() {
X, err := base.ParseCSVToInstances("train.csv", false)
So(err, ShouldEqual, nil)
Y, err := base.ParseCSVToInstances("test.csv", false)
So(err, ShouldEqual, nil)
_, err = NewLogisticRegression("l0", 1.0, 1e-6)
So(err, ShouldNotBeNil)
lr, err := NewLogisticRegression("l1", 1.0, 1e-6)
So(err, ShouldBeNil)
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 2", func() {
So(Z.RowString(1), ShouldEqual, "0")
})
})
So((*lr).String(), ShouldEqual, "LogisticRegression")
})
}