mirror of
https://github.com/sjwhitworth/golearn.git
synced 2025-04-25 13:48:49 +08:00
Format code
This commit is contained in:
parent
9bfe206c9c
commit
1e1b5f11fb
@ -1,12 +1,12 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
func TestId3(t *testing.T) {
|
||||
Convey("Doing a error test", t, func(){
|
||||
Convey("Doing a error test", t, func() {
|
||||
var _gerr GoLearnError
|
||||
gerr := &_gerr
|
||||
gerr.attachFormattedStack()
|
||||
|
@ -9,86 +9,86 @@ import (
|
||||
|
||||
func TestKnnClassifierCov(t *testing.T) {
|
||||
Convey("Test predict", t, func() {
|
||||
Convey("distance function", func(){
|
||||
trainingData, err := base.ParseCSVToInstances("knn_train_1.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
Convey("distance function", func() {
|
||||
trainingData, err := base.ParseCSVToInstances("knn_train_1.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
testingData, err := base.ParseCSVToInstances("knn_test_1.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
testingData, err := base.ParseCSVToInstances("knn_test_1.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("use euclidean", func(){
|
||||
cls := NewKnnClassifier("euclidean", "kdtree", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(err, ShouldBeNil)
|
||||
So(predictions, ShouldNotEqual, nil)
|
||||
result := base.GetClass(predictions, 0)
|
||||
So(result, ShouldEqual, "blue")
|
||||
})
|
||||
Convey("use euclidean", func() {
|
||||
cls := NewKnnClassifier("euclidean", "kdtree", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(err, ShouldBeNil)
|
||||
So(predictions, ShouldNotEqual, nil)
|
||||
result := base.GetClass(predictions, 0)
|
||||
So(result, ShouldEqual, "blue")
|
||||
})
|
||||
|
||||
Convey("use manhattan", func(){
|
||||
cls := NewKnnClassifier("manhattan", "kdtree", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(err, ShouldBeNil)
|
||||
So(predictions, ShouldNotEqual, nil)
|
||||
result := base.GetClass(predictions, 0)
|
||||
So(result, ShouldEqual, "blue")
|
||||
})
|
||||
Convey("use manhattan", func() {
|
||||
cls := NewKnnClassifier("manhattan", "kdtree", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(err, ShouldBeNil)
|
||||
So(predictions, ShouldNotEqual, nil)
|
||||
result := base.GetClass(predictions, 0)
|
||||
So(result, ShouldEqual, "blue")
|
||||
})
|
||||
|
||||
Convey("use cosine", func(){
|
||||
cls := NewKnnClassifier("cosine", "kdtree", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(err, ShouldBeNil)
|
||||
So(predictions, ShouldNotEqual, nil)
|
||||
result := base.GetClass(predictions, 0)
|
||||
So(result, ShouldEqual, "blue")
|
||||
})
|
||||
Convey("use cosine", func() {
|
||||
cls := NewKnnClassifier("cosine", "kdtree", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(err, ShouldBeNil)
|
||||
So(predictions, ShouldNotEqual, nil)
|
||||
result := base.GetClass(predictions, 0)
|
||||
So(result, ShouldEqual, "blue")
|
||||
})
|
||||
|
||||
Convey("use undefined distance function", func(){
|
||||
cls := NewKnnClassifier("abcd", "kdtree", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(predictions, ShouldBeNil)
|
||||
So(err.Error(), ShouldEqual, "unsupported distance function")
|
||||
})
|
||||
})
|
||||
Convey("use undefined distance function", func() {
|
||||
cls := NewKnnClassifier("abcd", "kdtree", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(predictions, ShouldBeNil)
|
||||
So(err.Error(), ShouldEqual, "unsupported distance function")
|
||||
})
|
||||
})
|
||||
|
||||
Convey("searching algorithm", func(){
|
||||
trainingData, err := base.ParseCSVToInstances("knn_train_1.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
Convey("searching algorithm", func() {
|
||||
trainingData, err := base.ParseCSVToInstances("knn_train_1.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
testingData, err := base.ParseCSVToInstances("knn_test_1.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
testingData, err := base.ParseCSVToInstances("knn_test_1.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("use undefined searching algorithm", func(){
|
||||
cls := NewKnnClassifier("cosine", "abcd", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(predictions, ShouldBeNil)
|
||||
So(err.Error(), ShouldEqual, "unsupported searching algorithm")
|
||||
})
|
||||
})
|
||||
Convey("use undefined searching algorithm", func() {
|
||||
cls := NewKnnClassifier("cosine", "abcd", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(predictions, ShouldBeNil)
|
||||
So(err.Error(), ShouldEqual, "unsupported searching algorithm")
|
||||
})
|
||||
})
|
||||
|
||||
Convey("check features", func(){
|
||||
Convey("use different dataset", func(){
|
||||
trainingData, err := base.ParseCSVToInstances("knn_train_1.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
testingData, err := base.ParseCSVToInstances("knn_test_2.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
cls := NewKnnClassifier("cosine", "linear", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(predictions, ShouldBeNil)
|
||||
So(err.Error(), ShouldEqual, "attributes not compatible")
|
||||
})
|
||||
})
|
||||
Convey("check features", func() {
|
||||
Convey("use different dataset", func() {
|
||||
trainingData, err := base.ParseCSVToInstances("knn_train_1.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
testingData, err := base.ParseCSVToInstances("knn_test_2.csv", false)
|
||||
So(err, ShouldBeNil)
|
||||
cls := NewKnnClassifier("cosine", "linear", 2)
|
||||
cls.AllowOptimisations = false
|
||||
cls.Fit(trainingData)
|
||||
predictions, err := cls.Predict(testingData)
|
||||
So(predictions, ShouldBeNil)
|
||||
So(err.Error(), ShouldEqual, "attributes not compatible")
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -9,12 +9,11 @@ import (
|
||||
//"fmt"
|
||||
)
|
||||
|
||||
|
||||
func TestLinearSVC(t *testing.T) {
|
||||
Convey("Doing a LinearSVC test", t, func(){
|
||||
Convey("Doing a LinearSVC test", t, func() {
|
||||
var SVC *LinearSVC
|
||||
var err error
|
||||
Convey("Test NewLinearSVC", func(){
|
||||
Convey("Test NewLinearSVC", func() {
|
||||
_, err = NewLinearSVC("l1", "l1", false, 1.0, -1e6)
|
||||
So(err, ShouldNotBeNil)
|
||||
_, err = NewLinearSVC("l0", "l1", false, 1.0, -1e6)
|
||||
@ -35,7 +34,7 @@ func TestLinearSVC(t *testing.T) {
|
||||
_, err = NewLinearSVC("l2", "l1", true, 1.0, -1e6)
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
So(func(){ SVC.GetMetadata() } , ShouldNotPanic)
|
||||
So(func() { SVC.GetMetadata() }, ShouldNotPanic)
|
||||
|
||||
params := &LinearSVCParams{0, []float64{0.0}, 1.0, -1e6, false, false}
|
||||
params = params.Copy()
|
||||
@ -60,7 +59,6 @@ func TestLinearSVC(t *testing.T) {
|
||||
err = SVC.Load("tmp")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
|
||||
inst, err := base.ParseCSVToInstances("../examples/datasets/iris_headers.csv", true)
|
||||
inst.RemoveClassAttribute(inst.AllAttributes()[4])
|
||||
inst.AddClassAttribute(inst.AllAttributes()[1])
|
||||
@ -76,7 +74,6 @@ func TestLinearSVC(t *testing.T) {
|
||||
})
|
||||
//err = SVC.Save("tmp")
|
||||
|
||||
|
||||
//var problem *Problem
|
||||
//var param *Parameter
|
||||
})
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func TestLogistic(t *testing.T) {
|
||||
Convey("Doing a logistic test", t, func(){
|
||||
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)
|
||||
|
@ -1,14 +1,14 @@
|
||||
package trees
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sjwhitworth/golearn/base"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"testing"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
|
||||
func TestId3(t *testing.T) {
|
||||
Convey("Doing a id3 test", t, func(){
|
||||
Convey("Doing a id3 test", t, func() {
|
||||
var rule DecisionTreeRule
|
||||
s := rule.String()
|
||||
So(s, ShouldNotBeNil)
|
||||
|
Loading…
x
Reference in New Issue
Block a user