code: def eval_stacked_ensemble(stacked_ensemble, session, path):
      """Evaluate stacked ensemble
  
      Args:
          stacked_ensemble (xcessiv.models.StackedEnsemble)
  
          session: Valid SQLAlchemy session
  
          path (str, unicode): Path to project folder
  
      Returns:
          stacked_ensemble (xcessiv.models.StackedEnsemble)
      """
      try:
          meta_features_list = []
          for base_learner in stacked_ensemble.base_learners:
              mf = np.load(base_learner.meta_features_path(path))
              if len(mf.shape) == 1:
                  mf = mf.reshape(-1, 1)
              meta_features_list.append(mf)
  
          secondary_features = np.concatenate(
              meta_features_list, axis=1
          )
  
          # Get data
          extraction = session.query(models.Extraction).first()
          return_splits_iterable = (
              functions.import_object_from_string_code(
                  extraction.meta_feature_generation["source"],
                  "return_splits_iterable",
              )
          )
          X, y = extraction.return_train_dataset()
  
          #  We need to retrieve original order of meta-features
          indices_list = [
              test_index
              for train_index, test_index in return_splits_iterable(
                  X, y
              )
          ]
          indices = np.concatenate(indices_list)
          X, y = X[indices], y[indices]
  
          est = stacked_ensemble.return_secondary_learner()
  
          return_splits_iterable_stacked_ensemble = (
              functions.import_object_from_string_code(
                  extraction.stacked_ensemble_cv["source"],
                  "return_splits_iterable",
              )
          )
          preds = []
          trues_list = []
          for (
              train_index,
              test_index,
          ) in return_splits_iterable_stacked_ensemble(
              secondary_features, y
          ):
              X_train, X_test = (
                  secondary_features[train_index],
                  secondary_features[test_index],
              )
              y_train, y_test = y[train_index], y[test_index]
              est = est.fit(X_train, y_train)
              preds.append(
                  getattr(
                      est,
                      stacked_ensemble.base_learner_origin.meta_feature_generator,
                  )(X_test)
              )
              trues_list.append(y_test)
          preds = np.concatenate(preds, axis=0)
          y_true = np.concatenate(trues_list)
  
          for (
              key
          ) in stacked_ensemble.base_learner_origin.metric_generators:
              metric_generator = functions.import_object_from_string_code(
                  stacked_ensemble.base_learner_origin.metric_generators[
                      key
                  ],
                  "metric_generator",
              )
              stacked_ensemble.individual_score[key] = metric_generator(
                  y_true, preds
              )
  
          stacked_ensemble.job_status = "finished"
          session.add(stacked_ensemble)
          session.commit()
          return stacked_ensemble
  
      except:
          session.rollback()
          stacked_ensemble.job_status = "errored"
          stacked_ensemble.description["error_type"] = repr(
              sys.exc_info()[0]
          )
          stacked_ensemble.description["error_value"] = repr(
              sys.exc_info()[1]
          )
          stacked_ensemble.description[
              "error_traceback"
          ] = traceback.format_exception(*sys.exc_info())
          session.add(stacked_ensemble)
          session.commit()
          raise
  
file_path: xcessiv/xcessiv/automatedruns.py
imports: from __future__ import absolute_import, print_function, division, unicode_literals
  from rq import get_current_job
  from xcessiv import functions
  from xcessiv import models
  from xcessiv import constants
  import numpy
  import os
  import sys
  import traceback
  from six import iteritems
  import numbers
  from bayes_opt import BayesianOptimization
label_desc: Use image node_id 4 for calling a global function with example usage: eval_stacked_ensemble(stacked_ensemble, session, path) and returns: stacked_ensemble