code: def _get_rf(
      X: np.ndarray,
      Y: np.ndarray,
      Yvar: np.ndarray,
      num_trees: int,
      max_features: Optional[str],
  ) -> RandomForestRegressor:
      """Fit a Random Forest model.
  
      Args:
          X: X
          Y: Y
          Yvar: Variance for Y
          num_trees: Number of trees
          max_features: Max features specifier
  
      Returns: Fitted Random Forest.
      """
      r = RandomForestRegressor(
          n_estimators=num_trees,
          max_features=max_features,
          bootstrap=True,
      )
      # pyre-fixme[16]: `RandomForestRegressor` has no attribute `estimators_`.
      r.estimators_ = [
          DecisionTreeRegressor() for i in range(r.n_estimators)
      ]
      for estimator in r.estimators_:
          # Parametric bootstrap
          y = np.random.normal(loc=Y[:, 0], scale=np.sqrt(Yvar[:, 0]))
          estimator.fit(X, y)
      return r
  
imports: from __future__ import annotations
  from typing import Any, List, Optional, Tuple
  import numpy
  import torch
  from ax.core.search_space import SearchSpaceDigest
  from ax.core.types import TCandidateMetadata
  from ax.models.torch.utils import _datasets_to_legacy_inputs
  from ax.models.torch_base import TorchModel
  from ax.utils.common.docutils import copy_doc
  from botorch.utils.datasets import SupervisedDataset
  from sklearn.ensemble import RandomForestRegressor
  from sklearn.tree import DecisionTreeRegressor
  from torch import Tensor
label_desc: Use image node_id 1 for calling a global function with example usage: _get_rf(X, Y, Yvar, num_trees, max_features) and returns: r