Exemplo n.º 1
0
    def learn_classifier(self, data):
        transformer = Orange.core.DomainContinuizer()
        transformer.multinomialTreatment = Orange.core.DomainContinuizer.NValues
        transformer.continuousTreatment = \
            Orange.core.DomainContinuizer.NormalizeBySpan
        transformer.classTreatment = Orange.core.DomainContinuizer.Ignore
        newdomain = transformer(data)
        newexamples = data.translate(newdomain)
        #print newexamples[0]
        params = {}
        parameters = []
        self.learner.normalization = False ## Normalization already done

        if self.svm_type in [1, 4]:
            numOfNuValues = 9
            if self.svm_type == SVMLearner.Nu_SVC:
                max_nu = max(self.max_nu(newexamples) - 1e-7, 0.0)
            else:
                max_nu = 1.0
            parameters.append(("nu", [i / 10.0 for i in range(1, 9) \
                                      if i / 10.0 < max_nu] + [max_nu]))
        else:
            parameters.append(("C", [2 ** a for a in  range(-5, 15, 2)]))
        if self.kernel_type == 2:
            parameters.append(("gamma", [2 ** a for a in range(-5, 5, 2)] + [0]))
        import orngWrap
        tunedLearner = orngWrap.TuneMParameters(object=self.learner,
                                                parameters=parameters,
                                                folds=self.folds)

        return SVMClassifierWrapper(tunedLearner(newexamples,
                                                 verbose=self.verbose))
Exemplo n.º 2
0
 def _normalize(self, data):
     dc = Orange.core.DomainContinuizer()
     dc.class_treatment = Orange.core.DomainContinuizer.Ignore
     dc.continuous_treatment = Orange.core.DomainContinuizer.NormalizeBySpan
     dc.multinomial_treatment = Orange.core.DomainContinuizer.NValues
     newdomain = dc(data)
     return data.translate(newdomain)
Exemplo n.º 3
0
 def __call__(self, data, weightId=0):
     continuizer = DomainContinuizer(zeroBased=self.zeroBased,
                                     multinomialTreatment=self.multinomialTreatment,
                                     continuousTreatment=self.continuousTreatment,
                                     classTreatment=self.classTreatment)
     c_domain = continuizer(data, weightId)
     return data.translate(c_domain)
Exemplo n.º 4
0
 def __call__(self, data, weightId=0):
     continuizer = DomainContinuizer(
         zeroBased=self.zeroBased,
         multinomialTreatment=self.multinomialTreatment,
         continuousTreatment=self.continuousTreatment,
         classTreatment=self.classTreatment)
     c_domain = continuizer(data, weightId)
     return data.translate(c_domain)
Exemplo n.º 5
0
 def _normalize(self, data):
     if self.use_non_meta:
         dc = preprocess.DomainContinuizer()
         dc.class_treatment = dc.Ignore
         dc.continuous_treatment = dc.NormalizeBySpan
         dc.multinomial_treatment = dc.NValues
         newdomain = dc(data)
         data = data.translate(newdomain)
     return data
Exemplo n.º 6
0
    def __call__(self, data, weight_id=None):
        if not isinstance(data.domain.class_var, variable.Discrete):
            raise TypeError("Can only learn a discrete class.")

        if data.domain.has_discrete_attributes(False) or self.normalization:
            dc = DomainContinuizer()
            dc.multinomial_treatment = self.multinomial_treatment
            dc.class_treatment = dc.Ignore
            dc.continuous_treatment = \
                    dc.NormalizeBySpan if self.normalization else dc.Leave
            c_domain = dc(data)
            data = data.translate(c_domain)

        return super(MultiClassSVMLearner, self).__call__(data, weight_id)