source: orange/docs/reference/rst/code/svm-custom-kernel.py @ 9889:3a754edd2092

Revision 9889:3a754edd2092, 1.1 KB checked in by markotoplak, 2 years ago (diff)

Fixed 2.5 examples that used Orange.distance.instances

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