-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion.py
More file actions
26 lines (22 loc) · 790 Bytes
/
question.py
File metadata and controls
26 lines (22 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Question:
def __init__(self, column, value):
self.column = column
self.value = value
def _is_numeric_(value):
return isinstance(value, int) or isinstance(value, float)
def match(self, example):
# Compare the feature value in an example to the
# feature value in this question.
val = example[self.column]
if _is_numeric_(val):
return val >= self.value
else:
return val == self.value
def __repr__(self):
# This is just a helper method to print
# the question in a readable format.
condition = "=="
if _is_numeric_(value):
condition = ">="
return "Is %s %s %s?" % (
header[self.column], condition, str(self.value))