code: def test_results_output_bayesian_search_optuna_ForecasterAutoreg_with_mocked():
      """
      Test output of _bayesian_search_optuna in ForecasterAutoreg with mocked
      (mocked done in Skforecast v0.4.3).
      """
      forecaster = ForecasterAutoreg(
          regressor=RandomForestRegressor(random_state=123),
          lags=2,  # Placeholder, the value will be overwritten
      )
  
      steps = 3
      n_validation = 12
      y_train = y[:-n_validation]
      lags_grid = [2, 4]
  
      def search_space(trial):
          search_space = {
              "n_estimators": trial.suggest_int("n_estimators", 10, 20),
              "min_samples_leaf": trial.suggest_float(
                  "min_samples_leaf", 0.1, 1.0, log=True
              ),
              "max_features": trial.suggest_categorical(
                  "max_features", ["log2", "sqrt"]
              ),
          }
  
          return search_space
  
      results = _bayesian_search_optuna(
          forecaster=forecaster,
          y=y,
          lags_grid=lags_grid,
          search_space=search_space,
          steps=steps,
          metric="mean_absolute_error",
          refit=True,
          initial_train_size=len(y_train),
          fixed_train_size=True,
          n_trials=10,
          random_state=123,
          return_best=False,
          verbose=False,
      )[0]
  
      expected_results = pd.DataFrame(
          {
              "lags": [
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2],
                  [1, 2],
                  [1, 2],
                  [1, 2],
                  [1, 2],
                  [1, 2, 3, 4],
                  [1, 2],
                  [1, 2, 3, 4],
                  [1, 2],
                  [1, 2],
                  [1, 2],
                  [1, 2, 3, 4],
                  [1, 2],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
              ],
              "params": [
                  {
                      "n_estimators": 13,
                      "min_samples_leaf": 0.42753938073418213,
                      "max_features": "sqrt",
                  },
                  {
                      "n_estimators": 14,
                      "min_samples_leaf": 0.782328520465639,
                      "max_features": "log2",
                  },
                  {
                      "n_estimators": 16,
                      "min_samples_leaf": 0.707020154488976,
                      "max_features": "log2",
                  },
                  {
                      "n_estimators": 16,
                      "min_samples_leaf": 0.707020154488976,
                      "max_features": "log2",
                  },
                  {
                      "n_estimators": 14,
                      "min_samples_leaf": 0.782328520465639,
                      "max_features": "log2",
                  },
                  {
                      "n_estimators": 12,
                      "min_samples_leaf": 0.14977928606210794,
                      "max_features": "sqrt",
                  },
                  {
                      "n_estimators": 13,
                      "min_samples_leaf": 0.42753938073418213,
                      "max_features": "sqrt",
                  },
                  {
                      "n_estimators": 14,
                      "min_samples_leaf": 0.3116628929828935,
                      "max_features": "log2",
                  },
                  {
                      "n_estimators": 14,
                      "min_samples_leaf": 0.3116628929828935,
                      "max_features": "log2",
                  },
                  {
                      "n_estimators": 17,
                      "min_samples_leaf": 0.21035794225904136,
                      "max_features": "log2",
                  },
                  {
                      "n_estimators": 17,
                      "min_samples_leaf": 0.21035794225904136,
                      "max_features": "log2",
                  },
                  {
                      "n_estimators": 17,
                      "min_samples_leaf": 0.19325882509735576,
                      "max_features": "sqrt",
                  },
                  {
                      "n_estimators": 15,
                      "min_samples_leaf": 0.2466706727024324,
                      "max_features": "sqrt",
                  },
                  {
                      "n_estimators": 17,
                      "min_samples_leaf": 0.2649149454284987,
                      "max_features": "log2",
                  },
                  {
                      "n_estimators": 15,
                      "min_samples_leaf": 0.2466706727024324,
                      "max_features": "sqrt",
                  },
                  {
                      "n_estimators": 14,
                      "min_samples_leaf": 0.1147302385573586,
                      "max_features": "sqrt",
                  },
                  {
                      "n_estimators": 17,
                      "min_samples_leaf": 0.2649149454284987,
                      "max_features": "log2",
                  },
                  {
                      "n_estimators": 17,
                      "min_samples_leaf": 0.19325882509735576,
                      "max_features": "sqrt",
                  },
                  {
                      "n_estimators": 14,
                      "min_samples_leaf": 0.1147302385573586,
                      "max_features": "sqrt",
                  },
                  {
                      "n_estimators": 12,
                      "min_samples_leaf": 0.14977928606210794,
                      "max_features": "sqrt",
                  },
              ],
              "mean_absolute_error": np.array(
                  [
                      0.2077587228,
                      0.2095295831,
                      0.2104587292,
                      0.2152253922,
                      0.2166138881,
                      0.2173338079,
                      0.2173997593,
                      0.2212038456,
                      0.2213244194,
                      0.2228916722,
                      0.2229839748,
                      0.2235827592,
                      0.2247429583,
                      0.2254556258,
                      0.2263380591,
                      0.2276488527,
                      0.2288371667,
                      0.2323304396,
                      0.2373974755,
                      0.2407737066,
                  ]
              ),
              "n_estimators": np.array(
                  [
                      13,
                      14,
                      16,
                      16,
                      14,
                      12,
                      13,
                      14,
                      14,
                      17,
                      17,
                      17,
                      15,
                      17,
                      15,
                      14,
                      17,
                      17,
                      14,
                      12,
                  ]
              ),
              "min_samples_leaf": np.array(
                  [
                      0.4275393807,
                      0.7823285205,
                      0.7070201545,
                      0.7070201545,
                      0.7823285205,
                      0.1497792861,
                      0.4275393807,
                      0.311662893,
                      0.311662893,
                      0.2103579423,
                      0.2103579423,
                      0.1932588251,
                      0.2466706727,
                      0.2649149454,
                      0.2466706727,
                      0.1147302386,
                      0.2649149454,
                      0.1932588251,
                      0.1147302386,
                      0.1497792861,
                  ]
              ),
              "max_features": [
                  "sqrt",
                  "log2",
                  "log2",
                  "log2",
                  "log2",
                  "sqrt",
                  "sqrt",
                  "log2",
                  "log2",
                  "log2",
                  "log2",
                  "sqrt",
                  "sqrt",
                  "log2",
                  "sqrt",
                  "sqrt",
                  "log2",
                  "sqrt",
                  "sqrt",
                  "sqrt",
              ],
          },
          index=pd.Index(
              [
                  17,
                  19,
                  15,
                  5,
                  9,
                  4,
                  7,
                  8,
                  18,
                  6,
                  16,
                  0,
                  2,
                  1,
                  12,
                  3,
                  11,
                  10,
                  13,
                  14,
              ],
              dtype="int64",
          ),
      ).sort_values(by="mean_absolute_error", ascending=True)
  
      pd.testing.assert_frame_equal(
          results, expected_results, check_dtype=False
      )
  
imports: import re
  import pytest
  import numpy
  import pandas
  import sys
  from sklearn.ensemble import RandomForestRegressor
  from sklearn.linear_model import Ridge
  from sklearn.metrics import mean_absolute_error
  from skforecast.ForecasterAutoreg import ForecasterAutoreg
  from skforecast.ForecasterAutoregCustom import ForecasterAutoregCustom
  from skforecast.model_selection import backtesting_forecaster
  from skforecast.model_selection.model_selection import _bayesian_search_optuna
  import optuna
  from optuna.samplers import TPESampler
  from tqdm import tqdm
  from functools import partialmethod
  from .fixtures_model_selection import y
label_desc: Use image node_id 4 for calling a global function with example usage: test_results_output_bayesian_search_optuna_ForecasterAutoreg_with_mocked() and returns: search_space