docstr: The `RandomForest` mixer supports both regression and classification tasks. 
  It inherits from sklearn.ensemble.RandomForestRegressor and sklearn.ensemble.RandomForestClassifier.
  (https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html)
  (https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html)
  
  :param stop_after: time budget in seconds.
  :param target: name of the target column that the mixer will learn to predict.
  :param dtype_dict: dictionary with dtypes of all columns in the data.
  :param fit_on_dev: whether to fit on the dev dataset.
  :param use_optuna: whether to activate the automated hyperparameter search (optuna-based). Note that setting this flag to `True` does not guarantee the search will run, rather, the speed criteria will be checked first (i.e., if a single iteration is too slow with respect to the time budget, the search will not take place). 
docstr_tok: ["The","`","RandomForest","`","mixer","supports","both","regression","and","classification","tasks",".","It","inherits","from","sklearn.ensemble.RandomForestRegressor","and","sklearn.ensemble.RandomForestClassifier",".","(","https",":","\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.ensemble.RandomForestRegressor.html",")","(","https",":","\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.ensemble.RandomForestClassifier.html",")",":","param","stop_after",":","time","budget","in","seconds",".",":","param","target",":","name","of","the","target","column","that","the","mixer","will","learn","to","predict",".",":","param","dtype_dict",":","dictionary","with","dtypes","of","all","columns","in","the","data",".",":","param","fit_on_dev",":","whether","to","fit","on","the","dev","dataset",".",":","param","use_optuna",":","whether","to","activate","the","automated","hyperparameter","search","(","optuna-based",")",".","Note","that","setting","this","flag","to","`","True","`","does","not","guarantee","the","search","will","run",",","rather",",","the","speed","criteria","will","be","checked","first","(","i.e.",",","if","a","single","iteration","is","too","slow","with","respect","to","the","time","budget",",","the","search","will","not","take","place",")","."]
code: def __init__(
      self,
      stop_after: float,
      target: str,
      dtype_dict: Dict[str, str],
      fit_on_dev: bool,
      target_encoder: BaseEncoder,
      use_optuna: bool = False,
  ):
      """
      The `RandomForest` mixer supports both regression and classification tasks.
      It inherits from sklearn.ensemble.RandomForestRegressor and sklearn.ensemble.RandomForestClassifier.
      (https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html)
      (https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html)
  
      :param stop_after: time budget in seconds.
      :param target: name of the target column that the mixer will learn to predict.
      :param dtype_dict: dictionary with dtypes of all columns in the data.
      :param fit_on_dev: whether to fit on the dev dataset.
      :param use_optuna: whether to activate the automated hyperparameter search (optuna-based). Note that setting this flag to `True` does not guarantee the search will run, rather, the speed criteria will be checked first (i.e., if a single iteration is too slow with respect to the time budget, the search will not take place).
      """  # noqa
      super().__init__(stop_after)
      self.target = target
      self.dtype_dict = dtype_dict
      self.fit_on_dev = fit_on_dev
      self.use_optuna = use_optuna
      self.target_encoder = target_encoder
  
      self.model = None
      self.positive_domain = False
      self.num_trials = 5
      self.cv = 3
      self.map = {}
  
      self.cls_dtypes = [
          dtype.categorical,
          dtype.binary,
          dtype.cat_tsarray,
      ]
      self.float_dtypes = [
          dtype.float,
          dtype.quantity,
          dtype.num_tsarray,
      ]
      self.num_dtypes = [dtype.integer] + self.float_dtypes
      self.supports_proba = dtype_dict[target] in self.cls_dtypes
      self.is_classifier = self.supports_proba
  
      self.stable = True
  
imports: import time
  import math
  import torch
  import numpy
  import pandas
  import optuna
  from typing import Dict, Union, Optional
  from optuna import trial
  from sklearn import clone
  from sklearn.metrics import mean_squared_error
  from sklearn.model_selection import check_cv, cross_val_predict
  from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
  from type_infer.dtype import dtype
  from lightwood.helpers.log import log
  from lightwood.encoder.base import BaseEncoder
  from lightwood.data.encoded_ds import EncodedDs, ConcatedEncodedDs
  from lightwood.mixer.base import BaseMixer
  from lightwood.api.types import PredictionArguments
label_desc: Use image node_id 1 to create a new RandomForest object from inherited base classes: BaseMixer with example: obj = RandomForest(stop_after, target, dtype_dict, fit_on_dev, target_encoder, use_optuna)