Ignore:
Timestamp:
03/28/12 15:25:12 (2 years ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Added normalization parameter to MultiClassSVMLearner. Changed how and when DomainContinuizer is used.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/classification/svm/__init__.py

    r10676 r10679  
    774774 
    775775    def __call__(self, data, weight_id=None): 
     776        if not isinstance(data.domain.class_var, variable.Discrete): 
     777            raise TypeError("Can only learn a discrete class.") 
     778 
    776779        if data.domain.has_discrete_attributes() or self.normalization: 
    777780            dc = Orange.data.continuization.DomainContinuizer() 
     
    792795    __new__ = _orange__new__(base=Orange.core.LinearLearner) 
    793796 
    794     def __init__(self, C=1.0, eps=0.01, **kwargs): 
     797    def __init__(self, C=1.0, eps=0.01, normalization=True, **kwargs): 
    795798        """\ 
    796799        :param C: Regularization parameter (default 1.0) 
     
    800803        :type eps: float 
    801804         
     805        :param normalization: Normalize the input data prior to learning 
     806            (default True) 
     807        :type normalization: bool 
     808         
    802809        """ 
    803810        self.C = C 
    804811        self.eps = eps 
     812        self.normalization = normalization 
    805813        for name, val in kwargs.items(): 
    806814            setattr(self, name, val) 
    807815 
    808816        self.solver_type = self.MCSVM_CS 
    809         self.preproc = default_preprocessor() 
    810  
    811     def __call__(self, instances, weight_id=None): 
    812         instances = self.preproc(instances) 
    813         classifier = super(MultiClassSVMLearner, self).__call__(instances, weight_id) 
    814         return classifier 
     817 
     818    def __call__(self, data, weight_id=None): 
     819        if not isinstance(data.domain.class_var, variable.Discrete): 
     820            raise TypeError("Can only learn a discrete class.") 
     821 
     822        if data.domain.has_discrete_attributes() or self.normalization: 
     823            dc = Orange.data.continuization.DomainContinuizer() 
     824            dc.multinomial_treatment = dc.NValues 
     825            dc.class_treatment = dc.Ignore 
     826            dc.continuous_treatment = \ 
     827                    dc.NormalizeBySpan if self.normalization else dc.Leave 
     828            c_domain = dc(data) 
     829            data = data.translate(c_domain) 
     830 
     831        return super(MultiClassSVMLearner, self).__call__(data, weight_id) 
    815832 
    816833#TODO: Unified way to get attr weights for linear SVMs. 
Note: See TracChangeset for help on using the changeset viewer.