code: def xgb_regression_learner(
      df: pd.DataFrame,
      features: List[str],
      target: str,
      learning_rate: float = 0.1,
      num_estimators: int = 100,
      extra_params: Dict[str, Any] = None,
      prediction_column: str = "prediction",
      weight_column: str = None,
      encode_extra_cols: bool = True,
  ) -> LearnerReturnType:
      """
      Fits an XGBoost regressor to the dataset. It first generates a DMatrix
      with the specified features and labels from `df`. Then it fits a XGBoost
      model to this DMatrix. Return the predict function for the model and the
      predictions for the input dataset.
  
      Parameters
      ----------
  
      df : pandas.DataFrame
          A Pandas' DataFrame with features and target columns.
          The model will be trained to predict the target column
          from the features.
  
      features : list of str
          A list os column names that are used as features for the model. All this names
          should be in `df`.
  
      target : str
          The name of the column in `df` that should be used as target for the model.
          This column should be numerical and continuous, since this is a regression model.
  
      learning_rate : float
          Float in range [0,1].
          Step size shrinkage used in update to prevents overfitting. After each boosting step,
          we can directly get the weights of new features. and eta actually shrinks the
          feature weights to make the boosting process more conservative.
          See the eta hyper-parameter in:
          http://xgboost.readthedocs.io/en/latest/parameter.html
  
      num_estimators : int
          Int in range [0, inf]
          Number of boosted trees to fit.
          See the n_estimators hyper-parameter in:
          http://xgboost.readthedocs.io/en/latest/python/python_api.html
  
      extra_params : dict, optional
          Dictionary in the format {"hyperparameter_name" : hyperparameter_value.
          Other parameters for the XGBoost model. See the list in:
          http://xgboost.readthedocs.io/en/latest/parameter.html
          If not passed, the default will be used.
  
      prediction_column : str
          The name of the column with the predictions from the model.
  
      weight_column : str, optional
          The name of the column with scores to weight the data.
  
      encode_extra_cols : bool (default: True)
          If True, treats all columns in `df` with name pattern fklearn_feat__col==val` as feature columns.
      """
  
      import xgboost as xgb
  
      weights = df[weight_column].values if weight_column else None
      params = extra_params if extra_params else {}
      params = assoc(params, "eta", learning_rate)
      params = (
          params
          if "objective" in params
          else assoc(params, "objective", "reg:linear")
      )
  
      features = (
          features
          if not encode_extra_cols
          else expand_features_encoded(df, features)
      )
  
      dtrain = xgb.DMatrix(
          df[features].values,
          label=df[target].values,
          weight=weights,
          feature_names=list(map(str, features)),
      )
  
      bst = xgb.train(params, dtrain, num_estimators)
  
      def p(
          new_df: pd.DataFrame, apply_shap: bool = False
      ) -> pd.DataFrame:
          dtest = xgb.DMatrix(
              new_df[features].values,
              feature_names=list(map(str, features)),
          )
          col_dict = {prediction_column: bst.predict(dtest)}
  
          if apply_shap:
              import shap
  
              explainer = shap.TreeExplainer(bst)
              shap_values = list(
                  explainer.shap_values(new_df[features])
              )
              shap_expected_value = explainer.expected_value
  
              shap_output = {
                  "shap_values": shap_values,
                  "shap_expected_value": np.repeat(
                      shap_expected_value, len(shap_values)
                  ),
              }
  
              col_dict = merge(col_dict, shap_output)
  
          return new_df.assign(**col_dict)
  
      p.__doc__ = learner_pred_fn_docstring(
          "xgb_regression_learner", shap=True
      )
  
      log = {
          "xgb_regression_learner": {
              "features": features,
              "target": target,
              "prediction_column": prediction_column,
              "package": "xgboost",
              "package_version": xgb.__version__,
              "parameters": assoc(
                  params, "num_estimators", num_estimators
              ),
              "feature_importance": bst.get_score(),
              "training_samples": len(df),
          },
          "object": bst,
      }
  
      return p, p(df), log
  
file_path: fklearn/src/fklearn/training/regression.py
imports: from typing import Any, Dict, List, Union
  import numpy
  import pandas
  from toolz import merge, curry, assoc
  from sklearn.linear_model import LinearRegression, ElasticNet
  from sklearn.gaussian_process import GaussianProcessRegressor, kernels
  from sklearn import __version__
  from fklearn.common_docstrings import learner_pred_fn_docstring, learner_return_docstring
  from fklearn.types import LearnerReturnType
  from fklearn.training.utils import log_learner_time, expand_features_encoded
label_desc: Use image node_id 2 for calling a global function with example usage: xgb_regression_learner(df, features, target, learning_rate, num_estimators, extra_params, prediction_column, weight_column, encode_extra_cols) and returns: p,  p,  log, new_df