def parse(self, inStream):
        newStream = inStream.split( )
        newAttribute = Attribute.factory(newStream[2])
        newAttribute.setName(newStream[1])

        for num in range(2, len(newStream)):
            if type(newAttribute) == NominalAttribute:
                newAttribute.addValue(newStream[num])
            else:
                pass
        self.add(newAttribute)
        self.setClassIndex(self.getSize()-1)
Esempio n. 2
0
 def nominalToBinary(self):
     newDataSet = DataSet()
     newAttributes = Attributes()
     for items in self.attributes.attributes:
         if len(items.domain) > 2:
             binaryDomain = bin(len(items.domain))
             for index, char in enumerate(str(binaryDomain)):
                 if index >= len(str(binaryDomain))-2:
                     pass
                 else:
                     newAttribute = Attribute.factory("nominal")
                     newAttribute.setName(items.name + str(index))
                     newAttribute.addValue(str(0))
                     newAttribute.addValue(str(1))
                     newAttributes.add(newAttribute)
         else:
             newAttributes.add(items)
     newDataSet.setAttributes(newAttributes)
     newDataSet.attributes.setClassIndex(len(newAttributes.attributes)-1)
     #ADJUST EXAMPLES NEXT
     return newDataSet
Esempio n. 3
0
 def nominalToBinary(self):
     newDataSet = DataSet()
     newAttributes = Attributes()
     for items in self.attributes.attributes:
         if len(items.domain) > 2:
             binaryDomain = bin(len(items.domain))
             for index, char in enumerate(str(binaryDomain)):
                 if index >= len(str(binaryDomain)) - 2:
                     pass
                 else:
                     newAttribute = Attribute.factory("nominal")
                     newAttribute.setName(items.name + str(index))
                     newAttribute.addValue(str(0))
                     newAttribute.addValue(str(1))
                     newAttributes.add(newAttribute)
         else:
             newAttributes.add(items)
     newDataSet.setAttributes(newAttributes)
     newDataSet.attributes.setClassIndex(len(newAttributes.attributes) - 1)
     #ADJUST EXAMPLES NEXT
     return newDataSet
Esempio n. 4
0
from Evaluator import Evaluator
from DataSet import DataSet

from Attributes import Attributes
from Attribute import Attribute

"""
classifier = ID3(sys.argv)
evaluator = Evaluator(sys.argv)
performance = evaluator.evaluate(classifier, sys.argv)

print performance
"""

testAttributes = Attributes()
testAttribute = Attribute.factory("n")
testAttribute.setName("make")
testAttribute.addValue("cannondale")
testAttribute.addValue("nishiki")
testAttribute.addValue("trek")
testAttribute2 = Attribute.factory("n")
testAttribute2.setName("random")
testAttribute2.addValue("bc")
testAttribute2.addValue("ad")

testAttributes.add(testAttribute)
testAttributes.add(testAttribute2)
print testAttributes

newDataSet = DataSet()
newAttributes = Attributes()