Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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))
- Question(0, 'Green')
- Is color == Green?
Add Comment
Please, Sign In to add comment