Ignore:
Timestamp:
03/23/12 14:26:35 (2 years ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Added test case for sparse svm learner.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/testing/unit/tests/test_svm.py

    r10584 r10617  
    11import Orange 
    2 from Orange.classification.svm import SVMLearner, MeasureAttribute_SVMWeights,\ 
    3                             LinearLearner, RFE, get_linear_svm_weights, \ 
     2from Orange.classification.svm import SVMLearner, SVMLearnerSparse, \ 
     3                            ScoreSVMWeights, LinearLearner, RFE, \ 
     4                            get_linear_svm_weights, \ 
    45                            example_weighted_sum 
    56                             
     
    133134 
    134135 
    135 #def to_sparse(data): 
    136 #    domain = Orange.data.Domain([], data.domain.class_var) 
    137 #    domain.add_metas(dict([(Orange.core.newmetaid(), v) for v in data.domain.attributes])) 
    138 #    return Orange.data.Table(domain, data) 
    139 # 
    140 #def sparse_data_iter(): 
    141 #    for name, (data, ) in testing.datasets_iter(datasets): 
    142 #        yield name, (to_sparse(data), ) 
    143 #     
    144 ## This needs sparse datasets.  
    145 #@testing.data_driven(data_iter=sparse_data_iter()) 
    146 #class BagOfWordsSVMTestCase(testing.LearnerTestCase): 
    147 #    LEARNER = SVMLearner(name="svm-bow", kernel_type=SVMLearner.Custom, kernelFunc=BagOfWords()) 
    148  
    149  
     136def to_sparse(data): 
     137    domain = Orange.data.Domain([], data.domain.class_var) 
     138    domain.add_metas(dict([(Orange.core.newmetaid(), v) for v in data.domain.attributes])) 
     139    return Orange.data.Table(domain, data) 
     140 
     141def sparse_data_iter(): 
     142    for name, (data, ) in testing.datasets_iter(datasets): 
     143        yield name, (to_sparse(data), ) 
     144 
     145@testing.data_driven(data_iter=sparse_data_iter()) 
     146class SparseSVMTestCase(testing.LearnerTestCase): 
     147    LEARNER = SVMLearnerSparse(name="svm-sparse") 
     148     
     149    @test_on_data 
     150    def test_learner_on(self, dataset): 
     151        testing.LearnerTestCase.test_learner_on(self, dataset) 
     152        svm_test_binary_classifier(self, dataset) 
     153 
     154  
    150155@datasets_driven(datasets=datasets) 
    151156class CustomWrapperSVMTestCase(testing.LearnerTestCase): 
     
    173178 
    174179@datasets_driven(datasets=datasets) 
    175 class TestMeasureAttr_LinWeights(testing.MeasureAttributeTestCase): 
    176     MEASURE = MeasureAttribute_SVMWeights() 
    177  
     180class TestScoreSVMWeights(testing.MeasureAttributeTestCase): 
     181    MEASURE = ScoreSVMWeights() 
     182     
    178183 
    179184@datasets_driven(datasets=["iris"]) 
Note: See TracChangeset for help on using the changeset viewer.