code: def score_estimator(
      estimator,
      X_train,
      X_test,
      df_train,
      df_test,
      target,
      weights,
      tweedie_powers=None,
  ):
      """Evaluate an estimator on train and test sets with different metrics"""
  
      metrics = [
          ("D² explained", None),  # Use default scorer if it exists
          ("mean abs. error", mean_absolute_error),
          ("mean squared error", mean_squared_error),
      ]
      if tweedie_powers:
          metrics += [
              (
                  "mean Tweedie dev p={:.4f}".format(power),
                  partial(mean_tweedie_deviance, power=power),
              )
              for power in tweedie_powers
          ]
  
      res = []
      for subset_label, X, df in [
          ("train", X_train, df_train),
          ("test", X_test, df_test),
      ]:
          y, _weights = df[target], df[weights]
          for score_label, metric in metrics:
              if isinstance(estimator, tuple) and len(estimator) == 2:
                  # Score the model consisting of the product of frequency and
                  # severity models.
                  est_freq, est_sev = estimator
                  y_pred = est_freq.predict(X) * est_sev.predict(X)
              else:
                  y_pred = estimator.predict(X)
  
              if metric is None:
                  if not hasattr(estimator, "score"):
                      continue
                  score = estimator.score(X, y, sample_weight=_weights)
              else:
                  score = metric(y, y_pred, sample_weight=_weights)
  
              res.append(
                  {
                      "subset": subset_label,
                      "metric": score_label,
                      "score": score,
                  }
              )
  
      res = (
          pd.DataFrame(res)
          .set_index(["metric", "subset"])
          .score.unstack(-1)
          .round(4)
          .loc[:, ["train", "test"]]
      )
      return res
  
file_path: scikit-learn/examples/linear_model/plot_tweedie_regression_insurance_claims.py
imports: from functools import partial
  import matplotlib.pyplot
  import numpy
  import pandas
  from sklearn.datasets import fetch_openml
  from sklearn.metrics import mean_absolute_error, mean_squared_error, mean_tweedie_deviance
  from sklearn.compose import ColumnTransformer
  from sklearn.pipeline import make_pipeline
  from sklearn.preprocessing import FunctionTransformer, KBinsDiscretizer, OneHotEncoder, StandardScaler
  from sklearn.linear_model import PoissonRegressor
  from sklearn.model_selection import train_test_split
  from sklearn.linear_model import GammaRegressor
  from sklearn.dummy import DummyRegressor
  from sklearn.linear_model import TweedieRegressor
  from sklearn.metrics import auc
label_desc: Use image node_id 3 for calling a global function with example usage: score_estimator(estimator, X_train, X_test, df_train, df_test, target, weights, tweedie_powers) and returns: res