How the “def match(self, example)” method is automatically calling and how the example arguments is working here?

datascience.stackexchange https://datascience.stackexchange.com/questions/27979

  •  31-10-2019
  •  | 
  •  

Question

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?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with datascience.stackexchange
scroll top