def apply(self):
        kernel = ["linear", "poly", "rbf", "sigmoid"][self.kernel_type]
        common_args = dict(
            kernel=kernel,
            degree=self.degree,
            gamma=self.gamma,
            coef0=self.coef0,
            tol=self.tol,
            max_iter=self.max_iter if self.limit_iter else -1,
            probability=True,
            preprocessors=self.preprocessors
        )
        if self.svmtype == 0:
            learner = SVMLearner(C=self.C, **common_args)
        else:
            learner = NuSVMLearner(nu=self.nu, **common_args)
        learner.name = self.learner_name
        classifier = None
        sv = None
        if self.data is not None:
            self.error(0)
            if not learner.check_learner_adequacy(self.data.domain):
                self.error(0, learner.learner_adequacy_err_msg)
            else:
                classifier = learner(self.data)
                classifier.name = self.learner_name
                sv = self.data[classifier.skl_model.support_]

        self.send("Learner", learner)
        self.send("Classifier", classifier)
        self.send("Support vectors", sv)
Esempio n. 2
0
 def __init__(self, **kwds):
     self.folds=4
     self.verbose=True
     SVMLearner.__init__(self, **kwds)
     self.learner = SVMLearner(**kwds)
     try: 
         self.multinomialTreatment = eval(kwds["multinomialTreatment"])
     except:
         self.multinomialTreatment = DomainContinuizer.NValues
     try:
         self.continuousTreatment = eval(kwds["continuousTreatment"])
     except:
         self.continuousTreatment = DomainContinuizer.NormalizeBySpan
     try:            
         self.classTreatment = eval(kwds["classTreatment"])
     except:
         self.classTreatment = DomainContinuizer.Ignore
Esempio n. 3
0
from Orange import data
from Orange import evaluation

from Orange.classification.svm import SVMLearner, kernels
from Orange.distance import Euclidean
from Orange.distance import Hamming

iris = data.Table("iris.tab")
l1 = SVMLearner()
l1.kernel_func = kernels.RBFKernelWrapper(Euclidean(iris), gamma=0.5)
l1.kernel_type = SVMLearner.Custom
l1.probability = True
c1 = l1(iris)
l1.name = "SVM - RBF(Euclidean)"

l2 = SVMLearner()
l2.kernel_func = kernels.RBFKernelWrapper(Hamming(iris), gamma=0.5)
l2.kernel_type = SVMLearner.Custom
l2.probability = True
c2 = l2(iris)
l2.name = "SVM - RBF(Hamming)"

l3 = SVMLearner()
l3.kernel_func = kernels.CompositeKernelWrapper(
    kernels.RBFKernelWrapper(Euclidean(iris), gamma=0.5),
    kernels.RBFKernelWrapper(Hamming(iris), gamma=0.5), l=0.5)
l3.kernel_type = SVMLearner.Custom
l3.probability = True
c3 = l1(iris)
l3.name = "SVM - Composite"
svm = Orange.classification.svm.SVMLearner(trn_data)

# Check the accuracy
print "\n" + "*" * 50
print "DEFAULT SVM"
print "Training Accuracy: " + str(compute_learner_accuracy(svm, trn_data))
print "Testing  Accuracy: " + str(compute_learner_accuracy(svm, tst_data))

# Cross Validation
from Orange.classification.svm import SVMLearner, kernels
from Orange.distance import Euclidean
from Orange.distance import Hamming

svm1 = SVMLearner()

svm2 = SVMLearner()
svm2.kernel_func = kernels.RBFKernelWrapper(Hamming(trn_data), gamma=0.5)
svm2.kernel_type = SVMLearner.Custom
svm2.probability = True

svm3 = SVMLearner(kernel_type=SVMLearner.Custom,
                  kernel_func=kernels.CompositeKernelWrapper(
                      kernels.RBFKernelWrapper(Euclidean(trn_data), gamma=0.5),
                      kernels.RBFKernelWrapper(Hamming(trn_data), gamma=0.5), l=0.5),
                  probability=False)
res = Orange.evaluation.testing.cross_validation([svm1, svm2, svm3], trn_data, folds=5)

print "\n" + "-" * 30
print "CROSS VALIDATION"
print "SVM 1 Accuracy: %.2f" % Orange.evaluation.scoring.CA(res)[0]
print "SVM 2 Accuracy: %.2f" % Orange.evaluation.scoring.CA(res)[1]