code: def test_regressor_evaluator(self):
      df1 = self.spark.createDataFrame(
          [
              (0.5, 1.0),
              (-0.5, -0.8),
              (2.0, 3.0),
          ],
          schema=["label", "prediction"],
      )
  
      local_df1 = df1.toPandas()
  
      mse_evaluator = RegressionEvaluator(
          metricName="mse",
          labelCol="label",
          predictionCol="prediction",
      )
  
      expected_mse = 0.4466666877269745
      mse = mse_evaluator.evaluate(df1)
      mse_local = mse_evaluator.evaluate(local_df1)
      np.testing.assert_almost_equal(mse, expected_mse)
      np.testing.assert_almost_equal(mse_local, expected_mse)
  
      rmse_evaluator = RegressionEvaluator(
          metricName="rmse",
          labelCol="label",
          predictionCol="prediction",
      )
  
      expected_rmse = 0.6683312709480042
      rmse = rmse_evaluator.evaluate(df1)
      rmse_local = rmse_evaluator.evaluate(local_df1)
      np.testing.assert_almost_equal(rmse, expected_rmse)
      np.testing.assert_almost_equal(rmse_local, expected_rmse)
  
      r2_evaluator = RegressionEvaluator(
          metricName="r2",
          labelCol="label",
          predictionCol="prediction",
      )
  
      expected_r2 = 0.5768420696258545
      r2 = r2_evaluator.evaluate(df1)
      r2_local = r2_evaluator.evaluate(local_df1)
      np.testing.assert_almost_equal(r2, expected_r2)
      np.testing.assert_almost_equal(r2_local, expected_r2)
  
      # Test save / load
      with tempfile.TemporaryDirectory() as tmp_dir:
          r2_evaluator.saveToLocal(f"{tmp_dir}/ev")
          loaded_evaluator = RegressionEvaluator.loadFromLocal(
              f"{tmp_dir}/ev"
          )
          assert loaded_evaluator.getMetricName() == "r2"
  
file_path: spark/python/pyspark/ml/tests/connect/test_legacy_mode_evaluation.py
imports: import unittest
  import tempfile
  import numpy
  from pyspark.sql import SparkSession
  from pyspark.testing.connectutils import should_test_connect, connect_requirement_message
label_desc: Use image node_id 1 for calling the EvaluationTestsMixin obj's underlying member method code with example usage: obj.test_regressor_evaluator() without return types