diff --git a/base/categorical.go b/base/categorical.go index 9012014..ddcffb1 100644 --- a/base/categorical.go +++ b/base/categorical.go @@ -10,7 +10,7 @@ import ( // - useful for representing classes. type CategoricalAttribute struct { Name string - values []string `json:"values"` + values []string } // MarshalJSON returns a JSON version of this Attribute. diff --git a/base/conversion.go b/base/conversion.go index 2c81eee..03fcf62 100644 --- a/base/conversion.go +++ b/base/conversion.go @@ -2,6 +2,7 @@ package base import ( "fmt" + "github.com/gonum/matrix/mat64" ) @@ -9,7 +10,7 @@ func checkAllAttributesAreFloat(attrs []Attribute) error { // Check that all the attributes are float for _, a := range attrs { if _, ok := a.(*FloatAttribute); !ok { - fmt.Errorf("All []Attributes to this method must be FloatAttributes") + return fmt.Errorf("All []Attributes to this method must be FloatAttributes") } } return nil diff --git a/base/filtered.go b/base/filtered.go index 5fc384f..0d4f77f 100644 --- a/base/filtered.go +++ b/base/filtered.go @@ -157,7 +157,7 @@ func (l *LazilyFilteredInstances) transformNewToOldAttribute(as AttributeSpec) ( func (l *LazilyFilteredInstances) Get(as AttributeSpec, row int) []byte { asOld, err := l.transformNewToOldAttribute(as) if err != nil { - panic(fmt.Sprintf("Attribute %s could not be resolved. (Error: %s)", as, err)) + panic(fmt.Sprintf("Attribute %s could not be resolved. (Error: %s)", as.String(), err.Error())) } byteSeq := l.src.Get(asOld, row) if l.unfilteredMap[as.attr] { @@ -177,7 +177,7 @@ func (l *LazilyFilteredInstances) MapOverRows(asv []AttributeSpec, mapFunc func( for i, a := range asv { old, err := l.transformNewToOldAttribute(a) if err != nil { - return fmt.Errorf("Couldn't fetch old Attribute: '%s'", a) + return fmt.Errorf("Couldn't fetch old Attribute: '%s'", a.String()) } oldAsv[i] = old } diff --git a/base/fixed.go b/base/fixed.go index c35df03..55e6014 100644 --- a/base/fixed.go +++ b/base/fixed.go @@ -69,7 +69,7 @@ func (f *FixedAttributeGroup) set(col int, row int, val []byte) { // Copy the value in copied := copy(f.alloc[offset:], val) if copied != f.size { - panic(fmt.Sprintf("set() terminated by only copying %d bytes", copied, f.size)) + panic(fmt.Sprintf("set() terminated by only copying %d bytes, should be %d", copied, f.size)) } row++ diff --git a/base/serialize.go b/base/serialize.go index 6c86f72..d85451e 100644 --- a/base/serialize.go +++ b/base/serialize.go @@ -132,9 +132,9 @@ func deserializeAttributes(data []byte) []Attribute { // Define a JSON shim Attribute type JSONAttribute struct { - Type string `json:type` - Name string `json:name` - Attr json.RawMessage `json:attr` + Type string `json:"type"` + Name string `json:"name"` + Attr json.RawMessage `json:"attr"` } var ret []Attribute diff --git a/clustering/clustering.go b/clustering/clustering.go index a4a8176..3636d5b 100644 --- a/clustering/clustering.go +++ b/clustering/clustering.go @@ -3,6 +3,7 @@ package clustering import ( "fmt" + "github.com/sjwhitworth/golearn/base" "github.com/sjwhitworth/golearn/metrics/pairwise" ) @@ -66,7 +67,7 @@ func (ref ClusterMap) Equals(other ClusterMap) (bool, error) { if c3, ok := clusterIdMap[c2]; ok { // what's our correspondance with c2? if c1 != c3 { // if c1 is not what we've currently got, error out - return false, fmt.Errorf("ref point %d (cluster %d) is assigned to a different cluster (%d) in ref %s", p, c2, c1, clusterIdMap) + return false, fmt.Errorf("ref point %d (cluster %d) is assigned to a different cluster (%d) in ref %+v", p, c2, c1, clusterIdMap) } } else { clusterIdMap[c2] = c1 @@ -97,7 +98,7 @@ func (ref ClusterMap) Equals(other ClusterMap) (bool, error) { for cOld := range other { cNew := clusterIdMap[cOld] if !arraysEqual(ref[cNew], other[cOld]) { - return false, fmt.Errorf("Re-labelled cluster %d => %d doesn't contain the same points (%s, %s)", cOld, cNew, ref[cNew], other[cOld]) + return false, fmt.Errorf("Re-labelled cluster %d => %d doesn't contain the same points (%d, %d)", cOld, cNew, ref[cNew], other[cOld]) } newMap[cNew] = other[cOld] } diff --git a/filters/binning.go b/filters/binning.go index d11b996..fb9ebf6 100644 --- a/filters/binning.go +++ b/filters/binning.go @@ -2,8 +2,9 @@ package filters import ( "fmt" - "github.com/sjwhitworth/golearn/base" "math" + + "github.com/sjwhitworth/golearn/base" ) // BinningFilter does equal-width binning for numeric @@ -31,7 +32,7 @@ func NewBinningFilter(d base.FixedDataGrid, bins int) *BinningFilter { } func (b *BinningFilter) String() string { - return fmt.Sprintf("BinningFilter(%d Attribute(s), %d bin(s)", b.attrs, b.bins) + return fmt.Sprintf("BinningFilter(%d Attribute(s), %d bin(s)", len(b.attrs), b.bins) } // Train computes and stores the bin values diff --git a/filters/chimerge_freq.go b/filters/chimerge_freq.go index 553c959..ebc85c8 100644 --- a/filters/chimerge_freq.go +++ b/filters/chimerge_freq.go @@ -4,11 +4,12 @@ import ( "fmt" ) +// FrequencyTableEntry is a struct holding a value and a map of frequency type FrequencyTableEntry struct { Value float64 Frequency map[string]int } func (t *FrequencyTableEntry) String() string { - return fmt.Sprintf("%.2f %s", t.Value, t.Frequency) + return fmt.Sprintf("%.2f %+v", t.Value, t.Frequency) } diff --git a/meta/bagging_test.go b/meta/bagging_test.go index c33c12c..8a8ca11 100644 --- a/meta/bagging_test.go +++ b/meta/bagging_test.go @@ -1,20 +1,21 @@ package meta import ( + "math/rand" + "testing" + "time" + "github.com/sjwhitworth/golearn/base" "github.com/sjwhitworth/golearn/evaluation" "github.com/sjwhitworth/golearn/filters" "github.com/sjwhitworth/golearn/trees" . "github.com/smartystreets/goconvey/convey" - "math/rand" - "testing" - "time" ) func BenchmarkBaggingRandomForestFit(t *testing.B) { inst, err := base.ParseCSVToInstances("../examples/datasets/iris_headers.csv", true) if err != nil { - t.Fatal("Unable to parse CSV to instances: %s", err.Error()) + t.Fatalf("Unable to parse CSV to instances: %s", err.Error()) } rand.Seed(time.Now().UnixNano()) @@ -39,7 +40,7 @@ func BenchmarkBaggingRandomForestFit(t *testing.B) { func BenchmarkBaggingRandomForestPredict(t *testing.B) { inst, err := base.ParseCSVToInstances("../examples/datasets/iris_headers.csv", true) if err != nil { - t.Fatal("Unable to parse CSV to instances: %s", err.Error()) + t.Fatalf("Unable to parse CSV to instances: %s", err.Error()) } rand.Seed(time.Now().UnixNano())