public double getInformationFor() { String attributeName = specification.getTarget(); Hashtable counts = new Hashtable(); foreach (Example e in examples) { String val = e.getAttributeValueAsString(attributeName); if (counts.Contains(val)) { counts[val] = (((int)counts[val]) + 1); } else { counts.Add(val, 1); } } //double totalTargetAttributeCount = 0; not used double[] data = new double[counts.Keys.Count]; IEnumerator iter = counts.Values.GetEnumerator(); for (int i = 0; i < data.Length; i++) { iter.MoveNext(); data[i] = double.Parse(iter.Current.ToString()); } data = Util.normalize(data); return(Util.information(data)); }
public static Example exampleFromString(string data, DataSetSpecification dataSetSpec, string separator) { Hashtable attributes = new Hashtable(); //ArrayList attributeValues = Arrays.asList(data.Split(separator.ToCharArray()[0])); string[] splitData = data.Split(separator.ToCharArray()[0]); ArrayList attributeValues = new ArrayList(); foreach (string str in splitData) { attributeValues.Add(str); } if (dataSetSpec.isValid(attributeValues)) { ArrayList names = dataSetSpec.getAttributeNames(); IEnumerator nameiter = names.GetEnumerator(); IEnumerator valueiter = attributeValues.GetEnumerator(); while (nameiter.MoveNext() && valueiter.MoveNext()) { string name = nameiter.Current.ToString(); AttributeSpecification attributeSpec = dataSetSpec.getAttributeSpecFor(name); Attribute attribute = attributeSpec.createAttribute(valueiter.Current.ToString()); //attributes.put(name,attribute); if (attributes.Contains(name)) { attributes[name] = attribute; } else { attributes.Add(name, attribute); } } string targetAttributeName = dataSetSpec.getTarget(); //AttributeSpecification attributeSpec =dataSetSpec.getAttributeSpecFor(targetAttributeName ); AttributeSpecification _attributeSpec = dataSetSpec.getAttributeSpecFor(targetAttributeName); return(new Example(attributes, (Attribute)attributes[targetAttributeName])); } else { throw new Exception("Unable to construct Example from " + data); } }
public static Example exampleFromString(string data,DataSetSpecification dataSetSpec,string separator) { Hashtable attributes = new Hashtable(); //ArrayList attributeValues = Arrays.asList(data.Split(separator.ToCharArray()[0])); string[] splitData = data.Split(separator.ToCharArray()[0]); ArrayList attributeValues = new ArrayList(); foreach (string str in splitData) { attributeValues.Add(str); } if (dataSetSpec.isValid(attributeValues)) { ArrayList names = dataSetSpec.getAttributeNames(); IEnumerator nameiter = names.GetEnumerator(); IEnumerator valueiter = attributeValues.GetEnumerator(); while(nameiter.MoveNext() && valueiter.MoveNext()) { string name = nameiter.Current.ToString(); AttributeSpecification attributeSpec = dataSetSpec.getAttributeSpecFor(name); Attribute attribute = attributeSpec.createAttribute(valueiter.Current.ToString()); //attributes.put(name,attribute); if (attributes.Contains(name)) attributes[name] = attribute; else attributes.Add(name,attribute); } string targetAttributeName = dataSetSpec.getTarget(); //AttributeSpecification attributeSpec =dataSetSpec.getAttributeSpecFor(targetAttributeName ); AttributeSpecification _attributeSpec =dataSetSpec.getAttributeSpecFor(targetAttributeName ); return new Example(attributes,(Attribute)attributes[targetAttributeName]); } else { throw new Exception("Unable to construct Example from " + data); } }