code: def gam_train_metrics_recalculate(family, bs):
      np.random.seed(1234)
      n_rows = 1000
  
      data = {
          "X1": np.random.randn(n_rows),
          "X2": np.random.randn(n_rows),
          "X3": np.random.randn(n_rows),
          "W": np.random.choice([10, 20], size=n_rows),
          "Y": np.random.choice(
              [0, 0, 0, 0, 0, 10, 20, 30], size=n_rows
          )
          + 0.1,
      }
  
      train = h2o.H2OFrame(pd.DataFrame(data))
      test = train.drop("W")
      print(train)
      h2o_model = H2OGeneralizedAdditiveEstimator(
          family=family,
          gam_columns=["X3"],
          weights_column="W",
          lambda_=0,
          bs=bs,
          tweedie_variance_power=1.5,
          tweedie_link_power=0,
      )
      h2o_model.train(x=["X1", "X2"], y="Y", training_frame=train)
  
      # force H2O to recalculate metrics instead just taking them from metrics cache
      train_clone = h2o.H2OFrame(pd.DataFrame(data))
  
      print(
          "GAM performance with test_data=train: {0}, with test_data=test: {1} and train=True: "
          "{2}".format(
              h2o_model.model_performance(test_data=train)._metric_json[
                  "MSE"
              ],
              h2o_model.model_performance(test_data=test)._metric_json[
                  "MSE"
              ],
              h2o_model.model_performance(train=True)._metric_json[
                  "MSE"
              ],
          )
      )
  
      assert (
          abs(
              h2o_model.model_performance(
                  test_data=train_clone
              )._metric_json["MSE"]
              - h2o_model.model_performance(train=True)._metric_json[
                  "MSE"
              ]
          )
          < 1e-6
      )
  
file_path: h2o-3/h2o-py/tests/testdir_algos/gam/pyunit_PUBDEV_8398_gam_train_metrics.py
imports: import sys
  import h2o
  from h2o.estimators.gam import H2OGeneralizedAdditiveEstimator
  import pandas
  import numpy
  from tests import pyunit_utils
label_desc: Use image node_id 1 for calling a global function with example usage: gam_train_metrics_recalculate(family, bs) without return types