Ejemplo n.º 1
0
Archivo: ml.py Proyecto: mdqyy/pyvision
def testSVM():
    svm = SVM()

    for i in iris_training:
        svm.addTraining(labels[i], iris_data[i, :])

    svm.train(verbose=1)

    success = 0.0
    total = 0.0
    for i in iris_testing:
        c = svm.predict(iris_data[i, :])
        #print c, labels[i]
        if c == labels[i]:
            success += 1
        total += 1
    print "SVM Rate:", success / total
Ejemplo n.º 2
0
    def train(self, C=None, Gamma=None, ilog=None, callback=None):
        # Create the SVM
        self.svm = SVM(svm_type=TYPE_C_SVC)

        # Add training data
        for sub_id, tiles in self.training_data.iteritems():
            for tile in tiles:
                self.svm.addTraining(sub_id, tile)

        # Train the SVM
        if C != None and Gamma != None:
            self.svm.train(C_range=C,
                           G_range=Gamma,
                           verbose=True,
                           callback=callback)
        else:
            #Automatic
            self.svm.train(verbose=True, callback=callback)
Ejemplo n.º 3
0
    table = pv.Table()
    values = {0: [], 1: []}

    correct = 0
    total = 0
    for each in testing:
        label = clsfy.predict(each[1], ilog=ilog)
        total += 1
        if label == each[0]:
            correct += 1

    rate = float(correct) / total

    if ilog: ilog.table(table)
    return rate


if __name__ == "__main__":
    from pyvision.vector.SVM import SVM

    svm = SVM(kernel='LINEAR', random_seed=30)
    ilog = pv.ImageLog()
    print "SVM rate:", genderClassifier(svm, ilog=None)

    svm = SVM(kernel='RBF', random_seed=30)
    ilog = pv.ImageLog()
    print "SVM rate:", genderClassifier(svm, ilog=None)

    ilog.show()
Ejemplo n.º 4
0
 def runSVM(self):
     svm = SVM()
     print "I am in the SVM module now"