code: def train_and_score(
      learner: "skll.learner.Learner",
      train_examples: FeatureSet,
      test_examples: FeatureSet,
      metric: str,
  ) -> Tuple[float, float, float]:
      """
      Train learner, generate predictions, and evaluate predictions.
  
      A utility method to train a given learner instance on the given
      training examples, generate predictions on the training set itself
      and also the given test set, and score those predictions using the
      given metric. The method returns the train and test scores.
  
      If the learner has its ``probability`` attribute set to ``True``, it will
      produce probability values as predictions rather than class indices.
      In this case, this function will compute the argmax over the probability
      values to find the most likely class index and use that.
  
      Note that this method needs to be a top-level function since it is
      called from within ``joblib.Parallel()`` and, therefore, needs to be
      picklable which it would not be as an instancemethod of the ``Learner``
      class.
  
      Parameters
      ----------
      learner : :class:`skll.learner.Learner`
          A SKLL ``Learner`` instance.
      train_examples : :class:`skll.data.featureset.FeatureSet`
          The training examples.
      test_examples : :class:`skll.data.featureset.FeatureSet`
          The test examples.
      metric : str
          The scoring function passed to ``use_score_func()``.
  
      Returns
      -------
      float
          Output of the score function applied to predictions of
          ``learner`` on ``train_examples``.
      float
          Output of the score function applied to predictions of
          ``learner`` on ``test_examples``.
      float
          The time taken in seconds to fit the ``learner`` on
          ``train_examples``.
      """
      # capture the time before we train the model
      start_time = time.time()
      _ = learner.train(
          train_examples, grid_search=False, shuffle=False
      )
  
      # compute the time it took to train the model
      fit_time = time.time() - start_time
  
      # get the train and test class probabilities or indices (not labels)
      train_predictions = learner.predict(
          train_examples, class_labels=False
      )
      test_predictions = learner.predict(
          test_examples, class_labels=False
      )
  
      # recall that voting learners return a tuple from `predict()`
      if isinstance(train_predictions, tuple):
          train_predictions = train_predictions[0]
      if isinstance(test_predictions, tuple):
          test_predictions = test_predictions[0]
  
      # if we got probabilities, then we need to run argmax over them
      # to convert them into indices; this needs to handle both
      # regular learners as well as voting learners
      if (hasattr(learner, "probability") and learner.probability) or (
          hasattr(learner, "voting") and learner.voting == "soft"
      ):
          train_predictions = np.argmax(train_predictions, axis=1)
          test_predictions = np.argmax(test_predictions, axis=1)
  
      # now get the training and test labels and convert them to indices
      # but make sure to include any unseen labels in the test data
      if (
          train_examples.labels is not None
          and test_examples.labels is not None
      ):
          if learner.model_type._estimator_type == "classifier":
              test_label_list = np.unique(test_examples.labels).tolist()
              train_and_test_label_dict = add_unseen_labels(
                  learner.label_dict, test_label_list
              )
              train_labels = np.array(
                  [
                      train_and_test_label_dict[label]
                      for label in train_examples.labels
                  ]
              )
              test_labels = np.array(
                  [
                      train_and_test_label_dict[label]
                      for label in test_examples.labels
                  ]
              )
          else:
              train_labels = train_examples.labels
              test_labels = test_examples.labels
  
      # now compute and return the scores
      train_score = use_score_func(
          metric, train_labels, train_predictions
      )
      test_score = use_score_func(metric, test_labels, test_predictions)
  
      return train_score, test_score, fit_time
  
imports: from __future__ import annotations
  import inspect
  import logging
  import sys
  import time
  from collections import Counter, defaultdict
  from csv import DictWriter, excel_tab
  from functools import wraps
  from importlib import import_module
  from pathlib import Path
  from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Set, Tuple, Type, Union
  import joblib
  import numpy
  import scipy.sparse
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.feature_selection import SelectKBest
  from sklearn.metrics import accuracy_score, confusion_matrix, precision_recall_fscore_support
  from sklearn.model_selection import KFold, LeaveOneGroupOut, ShuffleSplit, StratifiedKFold
  from skll.data import FeatureSet
  from skll.metrics import _CUSTOM_METRICS, _PREDEFINED_CUSTOM_METRICS, use_score_func
  from skll.types import ComputeEvalMetricsResults, ConfusionMatrix, FeaturesetIterator, FoldMapping, IdType, IndexIterator, LabelType, PathOrStr, SparseFeatureMatrix
  from skll.utils.constants import CLASSIFICATION_ONLY_METRICS, CORRELATION_METRICS, REGRESSION_ONLY_METRICS, UNWEIGHTED_KAPPA_METRICS, WEIGHTED_KAPPA_METRICS
  from skll.version import VERSION
label_desc: Use image node_id 12 for calling a global function with example usage: train_and_score(learner, train_examples, test_examples, metric) and returns: train_score,  test_score,  fit_time