Changeset 9012:b3b451ecacdb in orange


Ignore:
Timestamp:
09/24/11 11:32:35 (3 years ago)
Author:
miha <miha.stajdohar@…>
Branch:
default
Convert:
b12db81043a74a2365553a984e3e382ce57eb126
Message:

Refactored to Orange25.

Location:
orange/doc/Orange/rst/code
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orange/doc/Orange/rst/code/svm-custom-kernel.py

    r8991 r9012  
    1 from Orange import core 
    21from Orange import data 
    3 from Orange.classification import svm 
     2from Orange import evaluation 
     3 
     4from Orange.classification.svm import SVMLearner, kernels 
     5from Orange.distance.instances import EuclideanConstructor 
     6from Orange.distance.instances import HammingConstructor 
    47 
    58table = data.Table("iris.tab") 
    6 l1=svm.SVMLearner() 
    7 l1.kernel_func=svm.kernels.RBFKernelWrapper(core.ExamplesDistanceConstructor_Euclidean(table), gamma=0.5) 
    8 l1.kernel_type=svm.SVMLearner.Custom 
    9 l1.probability=True 
    10 c1=l1(table) 
    11 l1.name="SVM - RBF(Euclidean)" 
     9l1 = SVMLearner() 
     10l1.kernel_func = kernels.RBFKernelWrapper(EuclideanConstructor(table), gamma=0.5) 
     11l1.kernel_type = SVMLearner.Custom 
     12l1.probability = True 
     13c1 = l1(table) 
     14l1.name = "SVM - RBF(Euclidean)" 
    1215 
    13 l2=svm.SVMLearner() 
    14 l2.kernel_func=svm.kernels.RBFKernelWrapper( 
    15     core.ExamplesDistanceConstructor_Hamming(table), gamma=0.5) 
    16 l2.kernel_type=svm.SVMLearner.Custom 
    17 l2.probability=True 
    18 c2=l2(table) 
    19 l2.name="SVM - RBF(Hamming)" 
     16l2 = SVMLearner() 
     17l2.kernel_func = kernels.RBFKernelWrapper(HammingConstructor(table), gamma=0.5) 
     18l2.kernel_type = SVMLearner.Custom 
     19l2.probability = True 
     20c2 = l2(table) 
     21l2.name = "SVM - RBF(Hamming)" 
    2022 
    21 l3=svm.SVMLearner() 
    22 l3.kernel_func = svm.kernels.CompositeKernelWrapper( 
    23     svm.kernels.RBFKernelWrapper( 
    24     core.ExamplesDistanceConstructor_Euclidean(table), gamma=0.5), 
    25     svm.kernels.RBFKernelWrapper( 
    26     core.ExamplesDistanceConstructor_Hamming(table), gamma=0.5), l=0.5) 
    27 l3.kernel_type=svm.SVMLearner.Custom 
    28 l3.probability=True 
    29 c3=l1(table) 
    30 l3.name="SVM - Composite" 
    31          
    32 from Orange import evaluation 
     23l3 = SVMLearner() 
     24l3.kernel_func = kernels.CompositeKernelWrapper( 
     25    kernels.RBFKernelWrapper(EuclideanConstructor(table), gamma=0.5), 
     26    kernels.RBFKernelWrapper(HammingConstructor(table), gamma=0.5), l=0.5) 
     27l3.kernel_type = SVMLearner.Custom 
     28l3.probability = True 
     29c3 = l1(table) 
     30l3.name = "SVM - Composite" 
     31 
    3332tests = evaluation.testing.cross_validation([l1, l2, l3], table, folds=5) 
    34 [ca1, ca2, ca3]=evaluation.scoring.CA(tests) 
     33[ca1, ca2, ca3] = evaluation.scoring.CA(tests) 
     34 
    3535print l1.name, "CA:", ca1 
    3636print l2.name, "CA:", ca2 
  • orange/doc/Orange/rst/code/svm-easy.py

    r8991 r9012  
    88learners = [svm_easy, svm_normal] 
    99 
    10 from Orange import evaluation 
     10from Orange.evaluation import testing, scoring 
    1111 
    12 results = evaluation.testing.cross_validation(learners, table, folds=5) 
     12results = testing.cross_validation(learners, table, folds=5) 
    1313print "Name     CA        AUC" 
    14 for learner, CA, AUC in zip(learners, evaluation.scoring.CA(results), evaluation.scoring.AUC(results)): 
     14for learner,CA,AUC in zip(learners, scoring.CA(results), scoring.AUC(results)): 
    1515    print "%-8s %.2f      %.2f" % (learner.name, CA, AUC) 
Note: See TracChangeset for help on using the changeset viewer.