source: orange/docs/reference/rst/code/svm-custom-kernel.py @ 9724:318e91106d47

Revision 9724:318e91106d47, 1.1 KB checked in by markotoplak, 2 years ago (diff)

Renames in Orange.distance.

Line 
1from Orange import data
2from Orange import evaluation
3
4from Orange.classification.svm import SVMLearner, kernels
5from Orange.distance import Euclidean
6from Orange.distance import Hamming
7
8table = data.Table("iris.tab")
9l1 = SVMLearner()
10l1.kernel_func = kernels.RBFKernelWrapper(Euclidean(table), gamma=0.5)
11l1.kernel_type = SVMLearner.Custom
12l1.probability = True
13c1 = l1(table)
14l1.name = "SVM - RBF(Euclidean)"
15
16l2 = SVMLearner()
17l2.kernel_func = kernels.RBFKernelWrapper(Hamming(table), gamma=0.5)
18l2.kernel_type = SVMLearner.Custom
19l2.probability = True
20c2 = l2(table)
21l2.name = "SVM - RBF(Hamming)"
22
23l3 = SVMLearner()
24l3.kernel_func = kernels.CompositeKernelWrapper(
25    kernels.RBFKernelWrapper(Euclidean(table), gamma=0.5),
26    kernels.RBFKernelWrapper(Hamming(table), gamma=0.5), l=0.5)
27l3.kernel_type = SVMLearner.Custom
28l3.probability = True
29c3 = l1(table)
30l3.name = "SVM - Composite"
31
32tests = evaluation.testing.cross_validation([l1, l2, l3], table, 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.