code: def ks_metric(model, data):
      # Author: Megan Kurka
      # get model predictions
      y = (
          model.params.get("response_column")
          .get("actual")
          .get("column_name")
      )
      preds = model.predict(data)["YES"].cbind(data[y])
      preds.col_names = ["prediction", "actual"]
      # bin records into prediction deciles
      import numpy as np
  
      breaks = preds["prediction"].quantile(
          prob=list(np.arange(0.1, 1.0, 0.01))
      )
      breaks = list(breaks.as_data_frame()["predictionQuantiles"])
      preds["bin"] = "bin0"
      preds["bin"] = preds["bin"].asfactor()
      for i in range(len(breaks)):
          preds["bin"] = (preds["prediction"] > breaks[i]).ifelse(
              "bin" + str(i), preds["bin"]
          )
      # calculate ks
      ks_stats = (
          preds.group_by("bin")
          .min("prediction")
          .sum("actual")
          .count()
          .get_frame()
      )
      ks_stats = ks_stats.sort("min_prediction", ascending=[False])
      ks_stats["bin"]
      cum_event = (
          ks_stats["sum_actual"] / ks_stats["sum_actual"].sum()
      ).cumsum()
      cum_non_event = (
          (ks_stats["nrow"] - ks_stats["sum_actual"])
          / (ks_stats["nrow"] - ks_stats["sum_actual"]).sum()
      ).cumsum()
      return (cum_event - cum_non_event).max()
  
imports: import sys
  import h2o
  from h2o.estimators import H2OGradientBoostingEstimator, H2OXGBoostEstimator
  from tests import pyunit_utils
label_desc: Use image node_id 3 for calling a global function with example usage: ks_metric(model, data) and returns: unknown