Example #1
0
 def confusion_matrix(self, klass):
     for i in self.data:
         if i.classified_klass == None: 
             raise system.SystemError('Cannot calculate accuracy as one or more instance(s) are not classified')
     matrix = cm.ConfusionMatrix(klass)
     for i in self.data:
         matrix.count(i.klass_value, i.classified_klass)
     return matrix
Example #2
0
 def __init__(self, lower=0, upper=0, upper_includes_max=False):
     """
     any number within this range should be greater than or equal to self.lower and 
     less than (or less than equal to depending on whether it includes the max) self.upper
     """
     self.__delta_added = False
     if upper < lower:
         raise se.SystemError('Lower limit ' + str(lower) +
                              ' cannot be greater than the Upper limit ' +
                              str(upper) + ' in a range')
     self.__uninitialized = False
     if upper == lower == 0:
         self.__uninitialized = True
     self.lower, self.upper, self.__delta_added = lower, upper, False
     if upper_includes_max:
         self.upper += DELTA
         self.__delta_added = True
Example #3
0
 def split(self, parts):
     if self.lower == self.upper: return None
     size = self.upper - self.lower
     max_limit = self.upper
     if self.__delta_added:
         size -= DELTA
         max_limit -= DELTA
     each = size / parts
     if each < DELTA:
         raise se.SystemError(
             'Splitting of range resulted in elements smaller than delta ' +
             str(DELTA) + '.')
     lower, ranges = self.lower, []
     for i in range(parts - 1):
         ranges.append(Range(lower, lower + each))
         lower += each
     ranges.append(Range(lower, self.upper))
     return ranges
Example #4
0
 def __div(self, num, den):
     if num == 0: return 0;
     if den == 0: raise se.SystemError('Divide by Zero Error')
     return float(num)/ den
Example #5
0
 def __get_lines(self, file_path, ext):
     if file_path is None:
         raise se.SystemError('Cannot open file. File name not specified.')
     return cfile.File(file_path, ext).for_each_line(lambda line: line)