trainung_data = [
['Green', 3, 'Apple'],
['Yellow', 3, 'Apple'],
['Red', 1, 'Grape'],
['Red', 1, 'Grape'],
['Yellow', 3, 'Lemon'],
]
header = ["color", "diameter", "label"]
def is_numeric(value):
return isinstance(value, int) or isinstance(value, float)
class Question:
def __init__(self, column, value):
self.column = column
self.value = value
def match(self, example):
val = example[self.column]
if is_numeric(val):
return val>=self.value
else:
return val>=self.value
def __repr__(self):
condition = '=='
if is_numeric(self.value):
condition = '>='
return "Is %s %s %s?" % (header[self.column], condition, str(self.value))
Now if i call the class like:
Question(0, 'Green')
It give me output like this
Is color == Green?