Пример #1
0
 def testNonExistingDataSet(self):
     dataSetName = "not-existing-data-set"
     fetcher = DataFetcher()
     
     try:
         fetcher.fetchDataSet(dataSetName)
     except IOError:
         pass
Пример #2
0
 def testDataContainer(self):       
     dataSetName = 'buffer_dataset'
     container = DataFetcher().fetchDataSet(dataSetName)
     
     numberOfExamples = 2
     dataVectorLength = 1
     
     self.assertEqual(numberOfExamples, container.getDataSetSize())
     self.assertEqual(dataVectorLength, container.getDataVectorLength())     
Пример #3
0
    def testDataContainer(self):
        dataSetName = 'buffer_dataset'
        container = DataFetcher().fetchDataSet(dataSetName)

        numberOfExamples = 2
        dataVectorLength = 1

        self.assertEqual(numberOfExamples, container.getDataSetSize())
        self.assertEqual(dataVectorLength, container.getDataVectorLength())
Пример #4
0
    def testTrainBufferPerceptron(self):
        dataSetName = 'buffer_dataset'
        container = DataFetcher().fetchDataSet(dataSetName)

        perceptron = Perceptron(container, 0.1, 15)
        perceptron.train()

        weightVector = perceptron.getWeightVector()
        expectedLength = container.getDataVectorLength() + 1
        self.assertEqual(len(weightVector), expectedLength)
Пример #5
0
 def testTrainBufferPerceptron(self):
     dataSetName = 'buffer_dataset'
     container = DataFetcher().fetchDataSet(dataSetName)
            
     perceptron = Perceptron(container, 0.1, 15) 
     perceptron.train()
     
     weightVector = perceptron.getWeightVector()
     expectedLength = container.getDataVectorLength() + 1
     self.assertEqual(len(weightVector), expectedLength)
Пример #6
0
 def classifyDataSet(self, dataSetName, perceptron):
     
     self.log.info('Classifying dataset %s', dataSetName)
     container = DataFetcher().fetchDataSet(dataSetName)
     labels = container.getLabels()
     samples = container.getDataVectors()
     
     errors = 0
     for i, sample in enumerate(samples):
         
         cls = perceptron.classify(sample)               
         if cls != labels[i]:
             errors += 1
             self.log.info('Misclassified sample %s as %s', labels[i], cls)
             
     setSize = container.getDataSetSize()
              
     errorRate = errors * 1.0 / setSize * 100
     self.log.info('Error rate while classifying was %s', errorRate) 
Пример #7
0
    def classifyDataSet(self, dataSetName, perceptron):

        self.log.info('Classifying dataset %s', dataSetName)
        container = DataFetcher().fetchDataSet(dataSetName)
        labels = container.getLabels()
        samples = container.getDataVectors()

        errors = 0
        for i, sample in enumerate(samples):

            cls = perceptron.classify(sample)
            if cls != labels[i]:
                errors += 1
                self.log.info('Misclassified sample %s as %s', labels[i], cls)

        setSize = container.getDataSetSize()

        errorRate = errors * 1.0 / setSize * 100
        self.log.info('Error rate while classifying was %s', errorRate)
Пример #8
0
    def trainPerceptron(self, dataSetName, alpha, iterations):
        container = DataFetcher().fetchDataSet(dataSetName)
        perceptron = Perceptron(container, 0.1, 15)
        perceptron.train()

        return perceptron