Package nltk_lite :: Package contrib :: Package classify :: Module spearman :: Class Spearman
[hide private]
[frames] | no frames]

Class Spearman

source code

   ClassifyI --+    
               |    
AbstractClassify --+
                   |
                  Spearman


The Spearman-rho Classifier is a non-parametric measure of correlation between two
sets of ranked values
Spearman-rho classification is a supervised classifier. It needs to be trained
with representative examples of each class. From these examples the classifier
calculates the most probable classification of the sample.

                6 * sum((Ai - Bi)^2)
p = 1   -     -------------------------
                   (n^3) - n
                   
where A, B are the vectors of ranked objects
         n is the number of ranked objects being compared

Internal data structures:
_feature_dectector:
    holds a feature detector function
_classes:
    holds a list of classes supplied during trainning
_cls_rank:
    holds a dictionary of ordered lists,   
    the order of the list is deturnmined by:
    first ranked object is ordered first
    duplicate values are ordered in alphabetical order

Instance Methods [hide private]
 
__init__(self, feature_detector, crop_data=100) source code
 
train(self, gold)
trains the classifier
source code
 
get_class_dict(self, sample) source code
 
_spearman_ranked(self, sample) source code
 
_get_ranks(self, sample_dist) source code
 
__repr__(self) source code

Inherited from AbstractClassify: classes, get_class, get_class_list, get_class_probs, get_class_tuples

Method Details [hide private]

__init__(self, feature_detector, crop_data=100)
(Constructor)

source code 
Parameters:
  • feature_detector - feature detector produced function
  • crop_data - ranking beyond which features are ignored this produces a maximum rank for large data sets where the lower order values would offset the results

train(self, gold)

source code 

trains the classifier

Parameters:
  • classes - dictionary of class names to representative examples

    function takes representative examples of classes then creates ordered lists of ranked features indexed by class name and feature type

Overrides: ClassifyI.train

get_class_dict(self, sample)

source code 
Parameters:
  • text - sample to be classified

_spearman_ranked(self, sample)

source code 
Parameters:
  • text - sample to be classified

_get_ranks(self, sample_dist)

source code 
Parameters:
  • sample_dist - sample frequency distribution