class_docstr: a class to represent a single clause/rule of the form:
  "IF <literal1> AND <literal2> AND ... <literal_k> THEN predict class = 0 or 1"
class_docstr_tok: ["a","class","to","represent","a","single","clause\/rule","of","the","form",":","''","IF","<","literal1",">","AND","<","literal2",">","AND","...","<","literal_k",">","THEN","predict","class","=","0","or","1","''"]
docstr: Args:
      X: pandas dataframe
  
  Returns:
      a boolean array `res` of length `X.shape[0]` (no. of instances in X)
      `res[i] = True => this rule satisfies X[i]`
docstr_tok: ["Args",":","X",":","pandas","dataframe","Returns",":","a","boolean","array","`","res","`","of","length","`","X.shape","[","0","]","`","(","no",".","of","instances","in","X",")","`","res","[","i","]","=","True","=",">","this","rule","satisfies","X","[","i","]","`"]
code: def apply(self, X: pd.DataFrame):
      """
      Args:
          X: pandas dataframe
  
      Returns:
          a boolean array `res` of length `X.shape[0]` (no. of instances in X)
          `res[i] = True => this rule satisfies X[i]`
      """
      res = np.ones(X.shape[0], dtype="bool")  # index array
      for idx, pred in enumerate(self.predicates):
          f, op, th = pred
          if op == "<=" or op == "<":
              if idx == 0:
                  res = (X[f] <= th).to_numpy()
              else:
                  res = res * (X[f] <= th).to_numpy()
          elif op == ">" or op == ">=":
              if idx == 0:
                  res = (X[f] >= th).to_numpy()
              else:
                  res = res * (X[f] >= th).to_numpy()
          else:
              raise ValueError("op must be <= or >")
      return res
  
file_path: AIX360/aix360/algorithms/imd/rule.py
imports: from dataclasses import dataclass
  import numpy
  import pandas
label_desc: Use image node_id 5 for calling the Rule obj's underlying member method code with example usage: obj.apply(X) and returns: res