func ChiMBuildFrequencyTable(attr int, inst *base.Instances) []*FrequencyTableEntry { ret := make([]*FrequencyTableEntry, 0) var attribute *base.FloatAttribute attribute, ok := inst.GetAttr(attr).(*base.FloatAttribute) if !ok { panic("only use Chi-M on numeric stuff") } for i := 0; i < inst.Rows; i++ { value := inst.Get(i, attr) valueConv := attribute.GetUsrVal(value) class := inst.GetClass(i) // Search the frequency table for the value found := false for _, entry := range ret { if entry.Value == valueConv { found = true entry.Frequency[class] += 1 } } if !found { newEntry := &FrequencyTableEntry{ valueConv, make(map[string]int), } newEntry.Frequency[class] = 1 ret = append(ret, newEntry) } } return ret }
func main() { // Load in the iris dataset iris, err := base.ParseCSVToInstances("../datasets/iris_headers.csv", true) if err != nil { panic(err) } for _, a := range iris.AllAttributes() { // var ac base.CategoricalAttribute var af base.FloatAttribute s, err := json.Marshal(a) if err != nil { panic(err) } fmt.Println(string(s)) err = json.Unmarshal(s, &af) fmt.Println(af.String()) // err = json.Unmarshal(s, &ac) // fmt.Println(ac.String()) } }