public double getInformationFor() { String attributeName = specification.getTarget(); Dictionary <String, int> counts = new Dictionary <String, int>(); foreach (Example e in examples) { String val = e.getAttributeValueAsString(attributeName); if (counts.ContainsKey(val)) { counts[val]++; } else { counts.Add(val, 1); } } double[] data = new double[counts.Keys.Count]; int i = 0; foreach (string key in counts.Keys) { data[i] = counts[key]; i++; } data = Util.normalize(data); return(Util.information(data)); }
public static Example exampleFromString(String data, DataSetSpecification dataSetSpec, Char separator) { Dictionary<String, LearningAttribute> attributes = new Dictionary<String, LearningAttribute>(); List<String> attributeValues = new List<String>(); string [] vals = data.Split(new char[] { ' ', '\t', ',' }); foreach (string v in vals) { if (!String.IsNullOrWhiteSpace(v)) { attributeValues.Add(v); } } if (dataSetSpec.isValid(attributeValues)) { List<String> names = dataSetSpec.getAttributeNames(); List<String>.Enumerator nameiter = names.GetEnumerator(); List<String>.Enumerator valueiter = attributeValues.GetEnumerator(); while (nameiter.MoveNext() && valueiter.MoveNext()) { String name = nameiter.Current; AttributeSpecification attributeSpec = dataSetSpec .getAttributeSpecFor(name); LearningAttribute attribute = attributeSpec.createAttribute(valueiter.Current); attributes.Add(name, attribute); } String targetAttributeName = dataSetSpec.getTarget(); return new Example(attributes, attributes[targetAttributeName]); } else { throw new ApplicationException("Unable to construct Example from " + data); } }
public static Example exampleFromString(String data, DataSetSpecification dataSetSpec, Char separator) { Dictionary <String, LearningAttribute> attributes = new Dictionary <String, LearningAttribute>(); List <String> attributeValues = new List <String>(); string [] vals = data.Split(new char[] { ' ', '\t', ',' }); foreach (string v in vals) { if (!String.IsNullOrWhiteSpace(v)) { attributeValues.Add(v); } } if (dataSetSpec.isValid(attributeValues)) { List <String> names = dataSetSpec.getAttributeNames(); List <String> .Enumerator nameiter = names.GetEnumerator(); List <String> .Enumerator valueiter = attributeValues.GetEnumerator(); while (nameiter.MoveNext() && valueiter.MoveNext()) { String name = nameiter.Current; AttributeSpecification attributeSpec = dataSetSpec .getAttributeSpecFor(name); LearningAttribute attribute = attributeSpec.createAttribute(valueiter.Current); attributes.Add(name, attribute); } String targetAttributeName = dataSetSpec.getTarget(); return(new Example(attributes, attributes[targetAttributeName])); } else { throw new ApplicationException("Unable to construct Example from " + data); } }