Changeset 9131:8d15dfd2404e in orange


Ignore:
Timestamp:
10/20/11 17:16:44 (2 years ago)
Author:
mocnik <mocnik@…>
Branch:
default
Convert:
40697d5f310f723340f21d7eaa18dc137c66bf6f
Message:

Fixed bug (Mahalanobis to center) when there were missing values in data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/evaluation/reliability.py

    r9130 r9131  
    674674     
    675675    def __call__(self, examples, *args): 
    676         distance_constructor = Orange.distance.instances.MahalanobisConstructor() 
    677         distance = distance_constructor(examples) 
     676        dc = Orange.core.DomainContinuizer() 
     677        dc.classTreatment = Orange.core.DomainContinuizer.Ignore 
     678        dc.continuousTreatment = Orange.core.DomainContinuizer.NormalizeBySpan 
     679        dc.multinomialTreatment = Orange.core.DomainContinuizer.NValues 
     680         
     681        new_domain = dc(examples) 
     682        new_examples = examples.translate(new_domain) 
    678683         
    679684        X, _, _ = examples.to_numpy() 
    680685        example_avg = numpy.average(X, 0) 
    681686         
    682         average_example = Orange.data.Instance(examples.domain, list(example_avg) + ["?"]) 
    683          
    684         return MahalanobisToCenterClassifier(distance, average_example) 
     687        distance_constructor = Orange.distance.instances.MahalanobisConstructor() 
     688        distance = distance_constructor(new_examples) 
     689         
     690        average_example = Orange.data.Instance(new_examples.domain, list(example_avg) + ["?"]) 
     691         
     692        return MahalanobisToCenterClassifier(distance, average_example, new_domain) 
    685693 
    686694class MahalanobisToCenterClassifier: 
    687     def __init__(self, distance, average_example): 
     695    def __init__(self, distance, average_example, new_domain): 
    688696        self.distance = distance 
    689697        self.average_example = average_example 
     698        self.new_domain = new_domain 
    690699     
    691700    def __call__(self, example, *args): 
    692701         
    693          
    694         mahalanobis_to_center = self.distance(example, self.average_example) 
     702        ex = Orange.data.Instance(self.new_domain, example) 
     703         
     704        mahalanobis_to_center = self.distance(ex, self.average_example) 
    695705         
    696706        return [ Estimate(mahalanobis_to_center, ABSOLUTE, MAHAL_TO_CENTER_ABSOLUTE) ] 
Note: See TracChangeset for help on using the changeset viewer.