code: def metric_json_check():
      df = h2o.import_file(
          path=pyunit_utils.locate("smalldata/logreg/prostate.csv")
      )
  
      # Regression metric json
      reg_mod = H2OGradientBoostingEstimator(distribution="gaussian")
      reg_mod.train(
          x=list(range(3, df.ncol)), y="CAPSULE", training_frame=df
      )
      reg_met = reg_mod.model_performance()
      reg_metric_json_keys_have = list(reg_met._metric_json.keys())
      reg_metric_json_keys_desired = [
          "model_category",
          "description",
          "r2",
          "frame",
          "model_checksum",
          "MSE",
          "RMSE",
          "mae",
          "rmsle",
          "__meta",
          "_exclude_fields",
          "scoring_time",
          "predictions",
          "model",
          "duration_in_ms",
          "frame_checksum",
          "nobs",
          "mean_residual_deviance",
          "custom_metric_name",
          "custom_metric_value",
      ]
      reg_metric_diff = list(
          set(reg_metric_json_keys_have)
          - set(reg_metric_json_keys_desired)
      )
      assert not reg_metric_diff, (
          "There's a difference between the current ({0}) and the desired ({1}) regression "
          "metric json. The difference is {2}".format(
              reg_metric_json_keys_have,
              reg_metric_json_keys_desired,
              reg_metric_diff,
          )
      )
      # Regression metric json (GLM)
      reg_mod = H2OGeneralizedLinearEstimator(family="gaussian")
      reg_mod.train(
          x=list(range(3, df.ncol)), y="CAPSULE", training_frame=df
      )
      reg_met = reg_mod.model_performance()
      reg_metric_json_keys_have = list(reg_met._metric_json.keys())
      reg_metric_json_keys_desired = [
          "model_category",
          "description",
          "r2",
          "residual_degrees_of_freedom",
          "frame",
          "model_checksum",
          "MSE",
          "RMSE",
          "mae",
          "rmsle",
          "__meta",
          "_exclude_fields",
          "null_deviance",
          "scoring_time",
          "null_degrees_of_freedom",
          "predictions",
          "AIC",
          "loglikelihood",
          "model",
          "duration_in_ms",
          "frame_checksum",
          "nobs",
          "residual_deviance",
          "mean_residual_deviance",
          "custom_metric_name",
          "custom_metric_value",
      ]
      reg_metric_diff = list(
          set(reg_metric_json_keys_have)
          - set(reg_metric_json_keys_desired)
      )
      assert not reg_metric_diff, (
          "There's a difference between the current ({0}) and the desired ({1}) glm-regression "
          "metric json. The difference is {2}".format(
              reg_metric_json_keys_have,
              reg_metric_json_keys_desired,
              reg_metric_diff,
          )
      )
  
      # Binomial metric json
      bin_mod = H2OGradientBoostingEstimator(distribution="bernoulli")
      df["CAPSULE"] = df["CAPSULE"].asfactor()
      bin_mod.train(
          x=list(range(3, df.ncol)), y="CAPSULE", training_frame=df
      )
      bin_met = bin_mod.model_performance()
      bin_metric_json_keys_have = list(bin_met._metric_json.keys())
      bin_metric_json_keys_desired = [
          "cm",
          "AUC",
          "Gini",
          "model_category",
          "description",
          "mean_per_class_error",
          "r2",
          "frame",
          "model_checksum",
          "MSE",
          "RMSE",
          "__meta",
          "_exclude_fields",
          "gains_lift_table",
          "logloss",
          "scoring_time",
          "thresholds_and_metric_scores",
          "predictions",
          "max_criteria_and_metric_scores",
          "model",
          "duration_in_ms",
          "frame_checksum",
          "nobs",
          "domain",
          "custom_metric_name",
          "custom_metric_value",
          "pr_auc",
      ]
      bin_metric_diff = list(
          set(bin_metric_json_keys_have)
          - set(bin_metric_json_keys_desired)
      )
      assert not bin_metric_diff, (
          "There's a difference between the current ({0}) and the desired ({1}) binomial "
          "metric json. The difference is {2}".format(
              bin_metric_json_keys_have,
              bin_metric_json_keys_desired,
              bin_metric_diff,
          )
      )
  
      # Binomial metric json (GLM)
      bin_mod = H2OGeneralizedLinearEstimator(family="binomial")
      bin_mod.train(
          x=list(range(3, df.ncol)), y="CAPSULE", training_frame=df
      )
      bin_metric_json_keys_have = list(bin_met._metric_json.keys())
      bin_metric_json_keys_desired = [
          "cm",
          "frame",
          "residual_deviance",
          "max_criteria_and_metric_scores",
          "MSE",
          "RMSE",
          "frame_checksum",
          "nobs",
          "AIC",
          "loglikelihood",
          "logloss",
          "Gini",
          "predictions",
          "AUC",
          "description",
          "mean_per_class_error",
          "model_checksum",
          "duration_in_ms",
          "model_category",
          "gains_lift_table",
          "r2",
          "residual_degrees_of_freedom",
          "__meta",
          "_exclude_fields",
          "null_deviance",
          "scoring_time",
          "null_degrees_of_freedom",
          "model",
          "thresholds_and_metric_scores",
          "domain",
          "custom_metric_name",
          "custom_metric_value",
          "pr_auc",
      ]
      bin_metric_diff = list(
          set(bin_metric_json_keys_have)
          - set(bin_metric_json_keys_desired)
      )
      assert not bin_metric_diff, (
          "There's a difference between the current ({0}) and the desired ({1}) glm-binomial "
          "metric json. The difference is {2}".format(
              bin_metric_json_keys_have,
              bin_metric_json_keys_desired,
              bin_metric_diff,
          )
      )
  
      # Multinomial metric json
      df = h2o.import_file(
          path=pyunit_utils.locate(
              "smalldata/airlines/AirlinesTrain.csv.zip"
          )
      )
      myX = [
          "Origin",
          "Dest",
          "IsDepDelayed",
          "UniqueCarrier",
          "Distance",
          "fDayofMonth",
          "fDayOfWeek",
      ]
      myY = "fYear"
  
      mul_mod = H2OGradientBoostingEstimator(distribution="multinomial")
      mul_mod.train(x=myX, y=myY, training_frame=df)
      mul_met = mul_mod.model_performance()
      mul_metric_json_keys_have = list(mul_met._metric_json.keys())
      mul_metric_json_keys_desired = [
          "cm",
          "model_category",
          "description",
          "mean_per_class_error",
          "AUC",
          "pr_auc",
          "multinomial_auc_table",
          "multinomial_aucpr_table",
          "r2",
          "frame",
          "nobs",
          "model_checksum",
          "MSE",
          "RMSE",
          "__meta",
          "_exclude_fields",
          "logloss",
          "scoring_time",
          "predictions",
          "hit_ratio_table",
          "model",
          "duration_in_ms",
          "frame_checksum",
          "custom_metric_name",
          "custom_metric_value",
      ]
      mul_metric_diff = list(
          set(mul_metric_json_keys_have)
          - set(mul_metric_json_keys_desired)
      )
      assert not mul_metric_diff, (
          "There's a difference between the current ({0}) and the desired ({1}) multinomial "
          "metric json. The difference is {2}".format(
              mul_metric_json_keys_have,
              mul_metric_json_keys_desired,
              mul_metric_diff,
          )
      )
  
      # Clustering metric json
      df = h2o.import_file(
          path=pyunit_utils.locate("smalldata/iris/iris.csv")
      )
      from h2o.estimators.kmeans import H2OKMeansEstimator
  
      clus_mod = H2OKMeansEstimator(k=3, standardize=False)
      clus_mod.train(x=list(range(4)), training_frame=df)
      clus_met = clus_mod.model_performance()
      clus_metric_json_keys_have = list(clus_met._metric_json.keys())
      clus_metric_json_keys_desired = [
          "tot_withinss",
          "model_category",
          "description",
          "frame",
          "model_checksum",
          "MSE",
          "RMSE",
          "__meta",
          "_exclude_fields",
          "scoring_time",
          "betweenss",
          "predictions",
          "totss",
          "model",
          "duration_in_ms",
          "frame_checksum",
          "nobs",
          "centroid_stats",
          "custom_metric_name",
          "custom_metric_value",
      ]
      clus_metric_diff = list(
          set(clus_metric_json_keys_have)
          - set(clus_metric_json_keys_desired)
      )
      assert not clus_metric_diff, (
          "There's a difference between the current ({0}) and the desired ({1}) clustering "
          "metric json. The difference is {2}".format(
              clus_metric_json_keys_have,
              clus_metric_json_keys_desired,
              clus_metric_diff,
          )
      )
  
imports: import sys
  import h2o
  from tests import pyunit_utils
  from h2o.estimators.glm import H2OGeneralizedLinearEstimator
  from h2o.estimators.gbm import H2OGradientBoostingEstimator
label_desc: Use image node_id 1 for calling a global function with example usage: metric_json_check() without return types