1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-05-01 22:18:10 +08:00
golearn/filters/binning_test.go
2014-08-03 15:17:04 +01:00

41 lines
971 B
Go

package filters
import (
base "github.com/sjwhitworth/golearn/base"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestBinning(testEnv *testing.T) {
//
// Read the data
inst1, err := base.ParseCSVToInstances("../examples/datasets/iris_headers.csv", true)
if err != nil {
panic(err)
}
inst2, err := base.ParseCSVToInstances("../examples/datasets/iris_binned.csv", true)
if err != nil {
panic(err)
}
//
// Construct the binning filter
binAttr := inst1.AllAttributes()[0]
filt := NewBinningFilter(inst1, 10)
filt.AddAttribute(binAttr)
filt.Train()
inst1f := base.NewLazilyFilteredInstances(inst1, filt)
// Retrieve the categorical version of the original Attribute
//
// Create the LazilyFilteredInstances
// and check the values
Convey("Discretized version should match reference", testEnv, func() {
_, rows := inst1.Size()
for i := 0; i < rows; i++ {
So(inst1f.RowString(i), ShouldEqual, inst2.RowString(i))
}
})
}