Home | Trees | Indices | Help |
|
---|
|
1 # Natural Language Toolkit 2 # 3 # Author: Sumukh Ghodke <sumukh dot ghodke at gmail dot com> 4 # 5 # URL: <http://nltk.sf.net> 6 # This software is distributed under GPL, for license information see LICENSE.TXT 7 from nltk_lite.contrib.classifier.exceptions import invaliddataerror as inv 8 from nltk_lite import probability as prob 9 import math 103213 self.attributes = attributes 14 self.klass = klass 15 self.training = training 16 self.validate_training()1719 if not self.training.are_valid(self.klass, self.attributes): 20 raise inv.InvalidDataError('Training data invalid.') 21 if not self.can_handle_continuous_attributes() and self.attributes.has_continuous_attributes(): 22 raise inv.InvalidDataError('One or more attributes are continuous.')2325 raise AssertionError()2628 raise AssertionError()2934 _file_names = [] 35 for name in comma_sep_string.split(','): 36 _file_names.append(name.strip()) 37 return _file_names3840 position, min_entropy = 0, None 41 for index in range(len(values) -1): 42 first, second = values[:index + 1], values[index + 1:] 43 e = entropy(first) + entropy(second) 44 if min_entropy is None: min_entropy = e 45 if e < min_entropy: min_entropy, position = e, index 46 return [position, min_entropy]4749 freq_dist = prob.FreqDist() 50 for value in values: freq_dist.inc(value) 51 return entropy_of_freq_dist(freq_dist)5254 freq_dist = prob.FreqDist() 55 klasses = dictionary.keys() 56 for klass in klasses: 57 freq_dist.inc(klass, dictionary[klass]) 58 return entropy_of_freq_dist(freq_dist)59 66
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Wed May 16 22:47:44 2007 | http://epydoc.sourceforge.net |