code: def test_fit_model_via_design_matrix_various_algo(time_series_data):
      """Tests ``fit_model_via_design_matrix`` with various algos.
      This test is to insure that the implemented algorithms have the expected
      behaviuor. To that we check for the performance of the algorithms in terms
      of test error on simulated data."""
      x_train = time_series_data["x_train"]
      y_train = time_series_data["y_train"]
      x_test = time_series_data["x_test"]
      y_test = time_series_data["y_test"]
      # Small number of features to be used with unregularized / unstable algorithms
      feature_cols_minimal = [
          "growth",
          "sin1_toy",
          "cos1_toy",
          "sin2_toy",
          "cos2_toy",
          "sin1_tow",
          "cos1_tow",
          "sin2_tow",
          "cos2_tow",
      ]
  
      # We consider two cases:
      # (a) algorithms which are stable (handle large number of features)
      # (b) algorithms which are unstable (do not handle large number of features)
      # For (a) we test with large number of features and for (b) a small number of features.
      # Temporarily removes `lars` and `lasso_lars` since they have unstable performance
      # under linux and Mac.
      fit_algorithms = [
          "rf",
          "ridge",
          "lasso",
          # "lars",
          "gradient_boosting",
          # "lasso_lars",
          "sgd",
          "elastic_net",
      ]
      fit_algorithms_unstable = [
          "linear",
          "quantile_regression",
          "statsmodels_glm",
      ]
  
      # Expected error for each algo (in terms of R2):
      expected_r2_dict = {
          "rf": 0.96,
          "ridge": 0.92,
          "lasso": 0.98,
          # "lars": 0.97,
          "gradient_boosting": 0.98,
          # "lasso_lars": 0.98,
          "sgd": 0.93,
          "elastic_net": 0.97,
          "linear": 0.95,
          "quantile_regression": 0.97,
          "statsmodels_glm": 0.9,
      }
  
      # Case (a)
      for fit_algorithm in fit_algorithms:
          ml_model = fit_model_via_design_matrix(
              x_train=x_train,  # A large number of features appear in ``x_train``
              y_train=y_train,
              fit_algorithm=fit_algorithm,
          )
  
          y_test_pred = ml_model.predict(x_test)
  
          err = calc_pred_err(y_test, y_test_pred)
          r2 = err[(EvaluationMetricEnum.Correlation.get_metric_name())]
          assert r2 == pytest.approx(
              expected_r2_dict[fit_algorithm], rel=2e-2
          )
  
      # Case (b)
      for fit_algorithm in fit_algorithms_unstable:
          ml_model = fit_model_via_design_matrix(
              x_train=x_train[
                  feature_cols_minimal
              ],  # A small number of features only
              y_train=y_train,
              fit_algorithm=fit_algorithm,
          )
  
          y_test_pred = ml_model.predict(x_test[feature_cols_minimal])
  
          err = calc_pred_err(y_test, y_test_pred)
          r2 = err[(EvaluationMetricEnum.Correlation.get_metric_name())]
          assert r2 == pytest.approx(
              expected_r2_dict[fit_algorithm], rel=2e-2
          )
  
imports: import warnings
  import numpy
  import pandas
  import pytest
  import scipy
  from pandas.testing import assert_frame_equal
  from patsy import dmatrices
  from greykite.algo.common.ml_models import breakdown_regression_based_prediction
  from greykite.algo.common.ml_models import design_mat_from_formula
  from greykite.algo.common.ml_models import fit_ml_model
  from greykite.algo.common.ml_models import fit_ml_model_with_evaluation
  from greykite.algo.common.ml_models import fit_model_via_design_matrix
  from greykite.algo.common.ml_models import get_h_mat
  from greykite.algo.common.ml_models import get_intercept_col_from_design_mat
  from greykite.algo.common.ml_models import predict_ml
  from greykite.algo.common.ml_models import predict_ml_with_uncertainty
  from greykite.algo.uncertainty.conditional.conf_interval import predict_ci
  from greykite.common.constants import ERR_STD_COL
  from greykite.common.constants import QUANTILE_SUMMARY_COL
  from greykite.common.constants import TimeFeaturesEnum
  from greykite.common.evaluation import EvaluationMetricEnum
  from greykite.common.evaluation import calc_pred_err
  from greykite.common.features.timeseries_features import build_time_features_df
  from greykite.common.features.timeseries_features import fourier_series_multi_fcn
  from greykite.common.features.timeseries_features import get_fourier_col_name
  from greykite.common.python_utils import assert_equal
  from greykite.common.testing_utils import gen_sliced_df
label_desc: Use image node_id 8 for calling a global function with example usage: test_fit_model_via_design_matrix_various_algo(time_series_data) without return types