random-forest/question.py
Vylion 6f4987e179 📝 Added the Forest class
📝 Changed some format and definitions
📝 Added Out-of-Bag error calculation
2019-04-26 13:07:16 +02:00

26 lines
691 B
Python

def is_numeric(value):
# Test if a value is numeric
return isinstance(value, int) or isinstance(value, float)
class Question(object):
def __init__(self, fields, pos, value):
self.fields = fields
self.pos = pos
self.value = value
self.numeric = is_numeric(value)
def match(self, entry):
val = entry.data[self.pos]
if self.numeric:
return val and val > self.value
else:
return val == self.value
def __str__(self):
condition = self.numeric and ">" or "="
field = self.fields[self.pos]
return "Is {f} {cond} {val}?".format(f=field, cond=condition, val=self.value)