Changeset 9128:e7ff70b63b12 in orange


Ignore:
Timestamp:
10/20/11 16:21:47 (2 years ago)
Author:
mocnik <mocnik@…>
Branch:
default
Convert:
c9e77dc8b089468c58dd12c66f36a11450937a65
Message:

Added new reliability method: Mahalanobis distance to the centroid of data

File:
1 edited

Legend:

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

    r9118 r9128  
    180180import math 
    181181import warnings 
     182import numpy 
    182183 
    183184from collections import defaultdict 
     
    209210BLENDING_ABSOLUTE = 9 
    210211ICV_METHOD = 10 
     212MAHAL_TO_CENTER_ABSOLUTE = 13 
    211213 
    212214# Type of estimator constant 
     
    218220               3: "BAGV absolute", 4: "CNK signed", 5: "CNK absolute", 
    219221               6: "LCV absolute", 7: "BVCK_absolute", 8: "Mahalanobis absolute", 
    220                9: "BLENDING absolute", 10: "ICV", 11: "RF Variance", 12: "RF Std"} 
     222               9: "BLENDING absolute", 10: "ICV", 11: "RF Variance", 12: "RF Std", 
     223               13: "Mahalanobis to center"} 
    221224 
    222225select_with_repeat = Orange.core.MakeRandomIndicesMultiple() 
     
    658661        return [ Estimate(mahalanobis_distance, ABSOLUTE, MAHAL_ABSOLUTE) ] 
    659662 
     663class MahalanobisToCenter: 
     664    """ 
     665    :rtype: :class:`Orange.evaluation.reliability.MahalanobisToCenterClassifier` 
     666     
     667    Mahalanobis distance to center estimate is defined as `mahalanobis distance <http://en.wikipedia.org/wiki/Mahalanobis_distance>`_ to the 
     668    centroid of the data. 
     669 
     670     
     671    """ 
     672    def __init__(self): 
     673        pass 
     674     
     675    def __call__(self, examples, *args): 
     676        distance_constructor = Orange.distance.instances.MahalanobisConstructor() 
     677        distance = distance_constructor(examples) 
     678         
     679        X, _, _ = examples.to_numpy() 
     680        example_avg = numpy.average(X, 0) 
     681         
     682        average_example = Orange.data.Instance(examples.domain, list(example_avg) + ["?"]) 
     683         
     684        return MahalanobisToCenterClassifier(distance, average_example) 
     685 
     686class MahalanobisToCenterClassifier: 
     687    def __init__(self, distance, average_example): 
     688        self.distance = distance 
     689        self.average_example = average_example 
     690     
     691    def __call__(self, example, *args): 
     692         
     693         
     694        mahalanobis_to_center = self.distance(example, self.average_example) 
     695         
     696        return [ Estimate(mahalanobis_to_center, ABSOLUTE, MAHAL_TO_CENTER_ABSOLUTE) ] 
     697 
     698 
    660699class BaggingVarianceCNeighbours: 
    661700    """ 
Note: See TracChangeset for help on using the changeset viewer.