Guest User

Untitled

a guest
Feb 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. trainung_data = [
  2. ['Green', 3, 'Apple'],
  3. ['Yellow', 3, 'Apple'],
  4. ['Red', 1, 'Grape'],
  5. ['Red', 1, 'Grape'],
  6. ['Yellow', 3, 'Lemon'],
  7. ]
  8. header = ["color", "diameter", "label"]
  9. def is_numeric(value):
  10. return isinstance(value, int) or isinstance(value, float)
  11. class Question:
  12. def __init__(self, column, value):
  13. self.column = column
  14. self.value = value
  15.  
  16. def match(self, example):
  17. val = example[self.column]
  18. if is_numeric(val):
  19. return val>=self.value
  20. else:
  21. return val>=self.value
  22. def __repr__(self):
  23. condition = '=='
  24. if is_numeric(self.value):
  25. condition = '>='
  26. return "Is %s %s %s?" % (header[self.column], condition, str(self.value))
  27.  
  28. Question(0, 'Green')
  29.  
  30. Is color == Green?
Add Comment
Please, Sign In to add comment