source: orange/docs/reference/rst/code/svm-custom-kernel.py @ 9823:7f9c3f3c6474

Revision 9823:7f9c3f3c6474, 1.1 KB checked in by lanumek, 2 years ago (diff)

Changed names of data sets (table replaced with data or name of the data set).

Line 
1from Orange import data
2from Orange import evaluation
3
4from Orange.classification.svm import SVMLearner, kernels
5from Orange.distance.instances import EuclideanConstructor
6from Orange.distance.instances import HammingConstructor
7
8iris = data.Table("iris.tab")
9l1 = SVMLearner()
10l1.kernel_func = kernels.RBFKernelWrapper(EuclideanConstructor(iris), gamma=0.5)
11l1.kernel_type = SVMLearner.Custom
12l1.probability = True
13c1 = l1(iris)
14l1.name = "SVM - RBF(Euclidean)"
15
16l2 = SVMLearner()
17l2.kernel_func = kernels.RBFKernelWrapper(HammingConstructor(iris), gamma=0.5)
18l2.kernel_type = SVMLearner.Custom
19l2.probability = True
20c2 = l2(iris)
21l2.name = "SVM - RBF(Hamming)"
22
23l3 = SVMLearner()
24l3.kernel_func = kernels.CompositeKernelWrapper(
25    kernels.RBFKernelWrapper(EuclideanConstructor(iris), gamma=0.5),
26    kernels.RBFKernelWrapper(HammingConstructor(iris), gamma=0.5), l=0.5)
27l3.kernel_type = SVMLearner.Custom
28l3.probability = True
29c3 = l1(iris)
30l3.name = "SVM - Composite"
31
32tests = evaluation.testing.cross_validation([l1, l2, l3], iris, folds=5)
33[ca1, ca2, ca3] = evaluation.scoring.CA(tests)
34
35print l1.name, "CA:", ca1
36print l2.name, "CA:", ca2
37print l3.name, "CA:", ca3
Note: See TracBrowser for help on using the repository browser.