Beispiel #1
0
        public double getAttributeValueAsDouble(String attributeName)
        {
            LearningAttribute attribute = attributes[attributeName];

            if (attribute == null || !(attribute is NumericAttribute))
            {
                throw new ApplicationException(
                          "cannot return numerical value for non numeric attribute");
            }
            return(((NumericAttribute)attribute).valueAsDouble());
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        public Example numerize(
            Dictionary <String, Dictionary <String, int> > attrValueToNumber)
        {
            Dictionary <String, LearningAttribute> numerizedExampleData = new Dictionary <String, LearningAttribute>();

            foreach (String key in attributes.Keys)
            {
                LearningAttribute attribute = attributes[key];
                if (attribute is StringAttribute)
                {
                    int correspondingNumber = attrValueToNumber[key][
                        attribute.valueAsString()];
                    NumericAttributeSpecification spec = new NumericAttributeSpecification(
                        key);
                    numerizedExampleData.Add(key, new NumericAttribute(
                                                 correspondingNumber, spec));
                }
                else            // Numeric Attribute
                {
                    numerizedExampleData.Add(key, attribute);
                }
            }
            return(new Example(numerizedExampleData, numerizedExampleData[targetAttribute.name()]));
        }
Beispiel #4
0
    public Example(Dictionary<String, LearningAttribute> attributes,
            LearningAttribute targetAttribute)
    {
		this.attributes = attributes;
		this.targetAttribute = targetAttribute;
	}
Beispiel #5
0
 public Example(Dictionary <String, LearningAttribute> attributes,
                LearningAttribute targetAttribute)
 {
     this.attributes      = attributes;
     this.targetAttribute = targetAttribute;
 }