def satisfied(self, x):
# Define a mask for each row in x
mask = np.ones(len(x), dtype=bool)
# Test that all of the conditions pass
for condition in self.conditions:
if condition['type'] == CONTINUOUS:
comparison = self.comparator[condition['operator']]
x_column = x[:, condition['operand_index']]
operand = condition['operand']
mask &= comparison(x_column, operand)
elif condition['type'] == CATEGORICAL:
allowed = condition['values']
x_column = x[:, [condition['operand_index']]]
mask &= np.isclose(allowed, x_column).any(axis=1)
# If all of the conditions passed for a single row, we can conclude
# that this row satisfies this rule
return mask
评论列表
文章目录