docstr: data = main_data 
  name = cohort_name 
  var_name = name of the variable to slice/dice 
  operator: >, <, =, >=, <= 
  value = value of the variable  
docstr_tok: ["data","=","main_data","name","=","cohort_name","var_name","=","name","of","the","variable","to","slice\/dice","operator",":",">",",","<",",","=",",",">","=",",","<","=","value","=","value","of","the","variable"]
code: def add_cohort_metrics(
      self,
      df,
      var_name="",
      operator="",
      value="",
      is_classification=True,
  ):
      """
      data = main_data
      name = cohort_name
      var_name = name of the variable to slice/dice
      operator: >, <, =, >=, <=
      value = value of the variable
  
      """
      if value != "":
          # Extract filtered predicted values
          _, predicted, condition_predict = self.filtered_dataframe(
              df, "y_prediction", var_name, operator, value
          )
          # Extract filtered true labels
          _, true_values, condition_true = self.filtered_dataframe(
              df, "y_actual", var_name, operator, value
          )
          # calculate metrics
          if is_classification is True:
              if len(true_values) != 0:
                  (
                      accuracy,
                      precision,
                      recall,
                      fpr,
                      fnr,
                  ) = self.classification_cohort_metrics(
                      true_values, predicted
                  )
                  self.cohort_set[
                      condition_predict
                  ] = self.generate_classification_divs(
                      accuracy, precision, recall, fpr, fnr
                  )
              else:
                  pass
          else:
              if len(true_values) != 0:
                  mae, mse, r2 = self.regression_cohort_metrics(
                      true_values, predicted
                  )
                  # save these metrics to an array
                  self.cohort_set[
                      condition_predict
                  ] = self.generator_regression_divs(mae, mse, r2)
              else:
                  pass
      else:
          main_dataset, condition = self.filtered_dataframe(
              df, "y_prediction"
          )
          true_data, _ = self.filtered_dataframe(df, "y_actual")
          if is_classification is True:
              if len(true_data) != 0:
                  (
                      accuracy,
                      precision,
                      recall,
                      fpr,
                      fnr,
                  ) = self.classification_cohort_metrics(
                      true_data, main_dataset
                  )
                  self.cohort_set[
                      condition
                  ] = self.generate_classification_divs(
                      accuracy, precision, recall, fpr, fnr
                  )
              else:
                  pass
          else:
              if len(true_data) != 0:
                  mae, mse, r2 = self.regression_cohort_metrics(
                      true_data, main_dataset
                  )
                  # save these metrics to an array
                  self.cohort_set[
                      condition
                  ] = self.generator_regression_divs(mae, mse, r2)
              else:
                  pass
  
file_path: explainx/lib/cohort_analysis.py
imports: from imports import *
label_desc: Use image node_id 5 for calling the cohortAnalysis obj's underlying member method code with example usage: obj.add_cohort_metrics(df, var_name, operator, value, is_classification) without return types