code: def save_predictions(model, tag, partition):
      r"""Save the predictions to disk.
  
      Parameters
      ----------
      model : alphapy.Model
          The model object to save.
      tag : str
          A unique identifier for the output files, e.g., a date stamp.
      partition : alphapy.Partition
          Reference to the dataset.
  
      Returns
      -------
      preds : numpy array
          The prediction vector.
      probas : numpy array
          The probability vector.
  
      """
  
      # Extract model parameters.
  
      directory = model.specs["directory"]
      extension = model.specs["extension"]
      model_type = model.specs["model_type"]
      separator = model.specs["separator"]
  
      # Get date stamp to record file creation
      timestamp = get_datestamp()
  
      # Specify input and output directories
  
      input_dir = SSEP.join([directory, "input"])
      output_dir = SSEP.join([directory, "output"])
  
      # Read the prediction frame
      file_spec = "".join([datasets[partition], "*"])
      file_name = most_recent_file(input_dir, file_spec)
      file_name = file_name.split(SSEP)[-1].split(PSEP)[0]
      pf = read_frame(input_dir, file_name, extension, separator)
  
      # Cull records before the prediction date
  
      try:
          predict_date = model.specs["predict_date"]
          found_pdate = True
      except:
          found_pdate = False
  
      if found_pdate:
          pd_indices = pf[pf.date >= predict_date].index.tolist()
          pf = pf.iloc[pd_indices]
      else:
          pd_indices = pf.index.tolist()
  
      # Save predictions for all projects
  
      logger.info("Saving Predictions")
      output_file = USEP.join(["predictions", timestamp])
      preds = model.preds[(tag, partition)].squeeze()
      if found_pdate:
          preds = np.take(preds, pd_indices)
      pred_series = pd.Series(preds, index=pd_indices)
      df_pred = pd.DataFrame(pred_series, columns=["prediction"])
      write_frame(
          df_pred, output_dir, output_file, extension, separator
      )
  
      # Save probabilities for classification projects
  
      probas = None
      if model_type == ModelType.classification:
          logger.info("Saving Probabilities")
          output_file = USEP.join(["probabilities", timestamp])
          probas = model.probas[(tag, partition)].squeeze()
          if found_pdate:
              probas = np.take(probas, pd_indices)
          prob_series = pd.Series(probas, index=pd_indices)
          df_prob = pd.DataFrame(prob_series, columns=["probability"])
          write_frame(
              df_prob, output_dir, output_file, extension, separator
          )
  
      # Save ranked predictions
  
      logger.info("Saving Ranked Predictions")
      pf["prediction"] = pred_series
      if model_type == ModelType.classification:
          pf["probability"] = prob_series
          pf.sort_values("probability", ascending=False, inplace=True)
      else:
          pf.sort_values("prediction", ascending=False, inplace=True)
      output_file = USEP.join(["rankings", timestamp])
      write_frame(pf, output_dir, output_file, extension, separator)
  
      # Return predictions and any probabilities
      return preds, probas
  
imports: from alphapy.estimators import scorers
  from alphapy.estimators import xgb_score_map
  from alphapy.features import feature_scorers
  from alphapy.frame import read_frame
  from alphapy.frame import write_frame
  from alphapy.globals import Encoders
  from alphapy.globals import ModelType
  from alphapy.globals import Objective
  from alphapy.globals import Partition, datasets
  from alphapy.globals import PSEP, SSEP, USEP
  from alphapy.globals import SamplingMethod
  from alphapy.globals import Scalers
  from alphapy.utilities import get_datestamp
  from alphapy.utilities import most_recent_file
  from copy import copy
  from datetime import datetime
  import itertools
  import joblib
  from keras.models import load_model
  import logging
  import numpy
  import pandas
  from sklearn.calibration import CalibratedClassifierCV
  from sklearn.linear_model import LogisticRegression
  from sklearn.linear_model import RidgeCV
  from sklearn.metrics import accuracy_score
  from sklearn.metrics import auc
  from sklearn.metrics import average_precision_score
  from sklearn.metrics import balanced_accuracy_score
  from sklearn.metrics import brier_score_loss
  from sklearn.metrics import classification_report
  from sklearn.metrics import cohen_kappa_score
  from sklearn.metrics import confusion_matrix
  from sklearn.metrics import explained_variance_score
  from sklearn.metrics import f1_score
  from sklearn.metrics import log_loss
  from sklearn.metrics import mean_absolute_error
  from sklearn.metrics import mean_squared_error
  from sklearn.metrics import mean_squared_log_error
  from sklearn.metrics import median_absolute_error
  from sklearn.metrics import precision_score
  from sklearn.metrics import r2_score
  from sklearn.metrics import recall_score
  from sklearn.metrics import roc_auc_score
  from sklearn.metrics import roc_curve
  from sklearn.metrics.cluster import adjusted_rand_score
  from sklearn.model_selection import cross_val_score
  from sklearn.model_selection import train_test_split
  import sys
  import yaml
label_desc: Use image node_id 11 for calling a global function with example usage: save_predictions(model, tag, partition) and returns: preds,  probas