Changeset 9205:cc8a9c2bd0bf in orange


Ignore:
Timestamp:
11/14/11 16:14:57 (18 months ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
3716040913f250d3c0d2714eaecda5638242cd8e
Message:

Fixed binary class classification.
Using soft max function to convert the predicted values to class probabilities.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/regression/earth.py

    r9114 r9205  
    229229                               expanded_class=expanded_class) 
    230230     
     231     
     232def soft_max(values): 
     233    values = numpy.asarray(values) 
     234    return numpy.exp(values) / numpy.sum(numpy.exp(values)) 
     235 
    231236 
    232237class EarthClassifier(Orange.core.ClassifierFD): 
     
    267272        from Orange.statistics.distribution import Distribution 
    268273         
    269         if is_discrete(self.class_var): 
    270             winner = max(vals) #TODO: Handle ties. 
    271             value = winner.variable.get_value_from.transformer.value 
    272             value = self.class_var(value) 
     274        if not self.multi_flag and is_discrete(self.class_var): 
    273275            dist = Distribution(self.class_var) 
    274             dist[value] = 1.0 
     276            if len(self.class_var.values) == 2: 
     277                probs = [1 - float(vals[0]), float(vals[0])] 
     278            else: 
     279                probs = soft_max(map(float, vals)) 
     280                 
     281            for val, p in zip(self.class_var.values, probs): 
     282                dist[val] = p 
     283            value = dist.modus() 
    275284            vals, probs = [value], [dist] 
    276285        else: 
Note: See TracChangeset for help on using the changeset viewer.