code: def run_ensemble_models(
      model_dict, X_train, y_train, X_test, y_test, scoring, modeltype
  ):
      start_time = time.time()
      (
          model_name,
          bac_score_list,
          ac_score_list,
          p_score_list,
          r_score_list,
          f1_score_list,
      ) = ([], [], [], [], [], [])
      iteration = 0
      estimators = []
      estim_tuples = []
      for key, val in model_dict.items():
          estimator_name = key
          model_name.append(key)
          if str(val).split("(")[0] == "MultinomialNB":
              #### Multinomial models need only positive values!!
              val.fit(abs(X_train), y_train)
              y_pred = val.predict(abs(X_test))
          else:
              try:
                  val.fit(X_train, y_train)
                  y_pred = val.predict(X_test)
              except:
                  if modeltype != "Regression":
                      key = "Logistic_Regression"
                      val = LogisticRegression()
                  else:
                      key = "Linear_Regression"
                      val = LinearRegression()
                  val.fit(X_train, y_train)
          try:
              y_pred = val.predict(X_test)
          except:
              print("Error in ensemble models. Returning...")
              stacks = np.array([])
              return model_name, stacks
          if iteration == 0:
              stacks = copy.deepcopy(y_pred)
              iteration += 1
          else:
              stacks = np.c_[stacks, y_pred]
          if not isinstance(y_test, str):
              if modeltype == "Regression":
                  bac_score = np.sqrt(
                      mean_squared_error(y_test, y_pred)
                  )
                  estimators.append((estimator_name, val, bac_score))
                  estim_tuples.append((estimator_name, bac_score))
                  bac_score_list.append(bac_score)
                  ac_score_list.append(
                      mean_squared_error(y_test, y_pred)
                  )
                  p_score_list.append(
                      mean_absolute_error(y_test, y_pred)
                  )
                  model_comparison_df = pd.DataFrame(
                      [
                          model_name,
                          bac_score_list,
                          ac_score_list,
                          p_score_list,
                      ]
                  ).T
                  model_comparison_df.columns = [
                      "model_name",
                      "RMSE",
                      "MSE",
                      "MAE",
                  ]
                  model_comparison_df = model_comparison_df.sort_values(
                      by="RMSE", ascending=True
                  )
              else:
                  bac_score = balanced_accuracy_score(y_test, y_pred)
                  estimators.append((estimator_name, val, bac_score))
                  estim_tuples.append((estimator_name, bac_score))
                  bac_score_list.append(
                      balanced_accuracy_score(y_test, y_pred)
                  )
                  ac_score_list.append(accuracy_score(y_test, y_pred))
                  p_score_list.append(
                      precision_score(y_test, y_pred, average="macro")
                  )
                  r_score_list.append(
                      recall_score(y_test, y_pred, average="macro")
                  )
                  f1_score_list.append(
                      f1_score(y_test, y_pred, average="macro")
                  )
                  model_comparison_df = pd.DataFrame(
                      [
                          model_name,
                          bac_score_list,
                          ac_score_list,
                          p_score_list,
                          r_score_list,
                          f1_score_list,
                      ]
                  ).T
                  model_comparison_df.columns = [
                      "model_name",
                      "bal_accuracy_score",
                      "accuracy_score",
                      "ave_precision_score",
                      "ave_recall_score",
                      "ave_f1_score",
                  ]
                  model_comparison_df = model_comparison_df.sort_values(
                      by="bal_accuracy_score", ascending=False
                  )
      if not isinstance(y_test, str):
          data_frame = model_comparison_df.set_index(
              "model_name"
          ).astype(float)
          plt.figure(figsize=(10, 10))
          g = sns.heatmap(
              data_frame, annot=True, fmt="0.2f", cbar=False
          )
          g.set_xticklabels(
              g.get_xticklabels(), rotation=45, fontsize=12
          )
          g.set_yticklabels(
              g.get_yticklabels(), rotation=0, fontsize=12
          )
          print(
              "Time taken = %0.0f seconds" % (time.time() - start_time)
          )
          g.set_title("QuickML Ensembling Models Results", fontsize=18)
          f1_stats = dict(estim_tuples)
          try:
              if scoring in [
                  "logloss",
                  "rmse",
                  "mae",
                  "mape",
                  "RMSE",
                  "neg_mean_squared_error",
              ]:
                  best_model_name = min(
                      f1_stats.items(), key=operator.itemgetter(1)
                  )[0]
              else:
                  best_model_name = max(
                      f1_stats.items(), key=operator.itemgetter(1)
                  )[0]
              print(
                  "Based on trying multiple models, Best type of algorithm for this data set is %s"
                  % best_model_name
              )
          except:
              print(
                  "Could not detect best algorithm type from ensembling. Continuing..."
              )
      return model_name, stacks
  
imports: import pandas
  import numpy
  import matplotlib.pyplot
  import seaborn
  import warnings
  from sklearn.model_selection import cross_val_score, StratifiedShuffleSplit, TimeSeriesSplit
  from sklearn.svm import LinearSVC, LinearSVR
  from sklearn.linear_model import SGDRegressor, SGDClassifier
  from sklearn.model_selection import cross_val_score, StratifiedShuffleSplit, TimeSeriesSplit
  from sklearn.model_selection import ShuffleSplit, StratifiedKFold, KFold
  from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
  from sklearn.ensemble import BaggingRegressor, RandomForestClassifier, RandomForestRegressor
  from sklearn.ensemble import ExtraTreesClassifier, ExtraTreesRegressor
  from sklearn.linear_model import LogisticRegressionCV, LinearRegression, Ridge
  from sklearn.svm import LinearSVC, SVR, LinearSVR
  from sklearn.ensemble import AdaBoostClassifier, AdaBoostRegressor
  from sklearn.tree import DecisionTreeRegressor, DecisionTreeClassifier
  from sklearn.linear_model import Lasso, LassoCV, Ridge, RidgeCV, LassoLarsCV
  from sklearn.model_selection import cross_val_predict
  from sklearn.ensemble import ExtraTreesRegressor, ExtraTreesClassifier
  from sklearn.linear_model import LogisticRegression, LogisticRegressionCV, LinearRegression
  from sklearn.model_selection import GridSearchCV, StratifiedShuffleSplit
  from sklearn.naive_bayes import GaussianNB, MultinomialNB
  from sklearn.tree import DecisionTreeClassifier
  from sklearn.multiclass import OneVsRestClassifier
  from sklearn.neighbors import KNeighborsRegressor
  import time
  import pdb
  import time
  import copy
  import operator
  from sklearn.metrics import balanced_accuracy_score, accuracy_score, precision_score, recall_score, f1_score
  from sklearn.metrics import mean_absolute_error, mean_squared_error
  import copy
  from sklearn.linear_model import LinearRegression
  from sklearn.linear_model import LogisticRegression
label_desc: Use image node_id 2 for calling a global function with example usage: run_ensemble_models(model_dict, X_train, y_train, X_test, y_test, scoring, modeltype) and returns: model_name,  stacks, model_name,  stacks