mirror of
https://github.com/sjwhitworth/golearn.git
synced 2025-04-26 13:49:14 +08:00
commit
8f1bc62401
@ -39,5 +39,5 @@ type Attribute interface {
|
|||||||
// Tests whether two Attributes can be represented in the same pond
|
// Tests whether two Attributes can be represented in the same pond
|
||||||
// i.e. they're the same size, and their byte order makes them meaningful
|
// i.e. they're the same size, and their byte order makes them meaningful
|
||||||
// when considered together
|
// when considered together
|
||||||
Compatable(Attribute) bool
|
Compatible(Attribute) bool
|
||||||
}
|
}
|
||||||
|
@ -62,9 +62,9 @@ func (b *BinaryAttribute) Equals(other Attribute) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compatable checks whether this Attribute can be represented
|
// Compatible checks whether this Attribute can be represented
|
||||||
// in the same pond as another.
|
// in the same pond as another.
|
||||||
func (b *BinaryAttribute) Compatable(other Attribute) bool {
|
func (b *BinaryAttribute) Compatible(other Attribute) bool {
|
||||||
if _, ok := other.(*BinaryAttribute); !ok {
|
if _, ok := other.(*BinaryAttribute); !ok {
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
|
@ -141,9 +141,9 @@ func (Attr *CategoricalAttribute) Equals(other Attribute) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compatable checks that this CategoricalAttribute has the same
|
// Compatible checks that this CategoricalAttribute has the same
|
||||||
// values as another, in the same order.
|
// values as another, in the same order.
|
||||||
func (Attr *CategoricalAttribute) Compatable(other Attribute) bool {
|
func (Attr *CategoricalAttribute) Compatible(other Attribute) bool {
|
||||||
attribute, ok := other.(*CategoricalAttribute)
|
attribute, ok := other.(*CategoricalAttribute)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
|
@ -180,8 +180,8 @@ func (inst *DenseInstances) addAttributeToAttributeGroup(newAttribute Attribute,
|
|||||||
id := inst.agMap[ag]
|
id := inst.agMap[ag]
|
||||||
p := inst.ags[id]
|
p := inst.ags[id]
|
||||||
for i, a := range p.Attributes() {
|
for i, a := range p.Attributes() {
|
||||||
if !a.Compatable(newAttribute) {
|
if !a.Compatible(newAttribute) {
|
||||||
return AttributeSpec{-1, 0, nil}, fmt.Errorf("Attribute %s is not compatable with %s in pond '%s' (position %d)", newAttribute, a, ag, i)
|
return AttributeSpec{-1, 0, nil}, fmt.Errorf("Attribute %s is not Compatible with %s in pond '%s' (position %d)", newAttribute, a, ag, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ func NewFloatAttribute(name string) *FloatAttribute {
|
|||||||
return &FloatAttribute{name, 2}
|
return &FloatAttribute{name, 2}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compatable checks whether this FloatAttribute can be ponded with another
|
// Compatible checks whether this FloatAttribute can be ponded with another
|
||||||
// Attribute (checks if they're both FloatAttributes)
|
// Attribute (checks if they're both FloatAttributes)
|
||||||
func (Attr *FloatAttribute) Compatable(other Attribute) bool {
|
func (Attr *FloatAttribute) Compatible(other Attribute) bool {
|
||||||
_, ok := other.(*FloatAttribute)
|
_, ok := other.(*FloatAttribute)
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
@ -239,9 +239,9 @@ func SampleWithReplacement(from FixedDataGrid, size int) FixedDataGrid {
|
|||||||
return NewInstancesViewFromRows(from, rowMap)
|
return NewInstancesViewFromRows(from, rowMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckCompatable checks whether two DataGrids have the same Attributes
|
// CheckCompatible checks whether two DataGrids have the same Attributes
|
||||||
// and if they do, it returns them.
|
// and if they do, it returns them.
|
||||||
func CheckCompatable(s1 FixedDataGrid, s2 FixedDataGrid) []Attribute {
|
func CheckCompatible(s1 FixedDataGrid, s2 FixedDataGrid) []Attribute {
|
||||||
s1Attrs := s1.AllAttributes()
|
s1Attrs := s1.AllAttributes()
|
||||||
s2Attrs := s2.AllAttributes()
|
s2Attrs := s2.AllAttributes()
|
||||||
interAttrs := AttributeIntersect(s1Attrs, s2Attrs)
|
interAttrs := AttributeIntersect(s1Attrs, s2Attrs)
|
||||||
|
@ -46,8 +46,8 @@ func (KNN *KNNClassifier) Predict(what base.FixedDataGrid) base.FixedDataGrid {
|
|||||||
panic("unsupported distance function")
|
panic("unsupported distance function")
|
||||||
|
|
||||||
}
|
}
|
||||||
// Check compatability
|
// Check Compatibility
|
||||||
allAttrs := base.CheckCompatable(what, KNN.TrainingData)
|
allAttrs := base.CheckCompatible(what, KNN.TrainingData)
|
||||||
if allAttrs == nil {
|
if allAttrs == nil {
|
||||||
// Don't have the same Attributes
|
// Don't have the same Attributes
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user