code: def predictions_to_instances(data, preds):
      
      if len(preds) == 0:
          return None
  
      is_numeric = isinstance(preds[0], NumericPrediction)
  
      # create header
      atts = []
      if is_numeric:
          atts.append(Attribute.create_numeric("index"))
          atts.append(Attribute.create_numeric("weight"))
          atts.append(Attribute.create_numeric("actual"))
          atts.append(Attribute.create_numeric("predicted"))
          atts.append(Attribute.create_numeric("error"))
      else:
          atts.append(Attribute.create_numeric("index"))
          atts.append(Attribute.create_numeric("weight"))
          atts.append(data.class_attribute.copy(name="actual"))
          atts.append(data.class_attribute.copy(name="predicted"))
          atts.append(Attribute.create_nominal("error", ["no", "yes"]))
          atts.append(Attribute.create_numeric("classification"))
          for i in range(data.class_attribute.num_values):
              atts.append(Attribute.create_numeric("distribution-" + data.class_attribute.value(i)))
  
      result = Instances.create_instances("Predictions", atts, len(preds))
  
      count = 0
      for pred in preds:
          count += 1
          if is_numeric:
              values = array([count, pred.weight, pred.actual, pred.predicted, pred.error])
          else:
              if pred.actual == pred.predicted:
                  error = 0.0
              else:
                  error = 1.0
              l = [count, pred.weight, pred.actual, pred.predicted, error, max(pred.distribution)]
              for i in range(data.class_attribute.num_values):
                  l.append(pred.distribution[i])
              values = array(l)
          inst = Instance.create_instance(values)
          result.add_instance(inst)
  
      return result
docs: Turns the predictions turned into an Instances object.
  
      :param data: the original dataset format
      :type data: Instances
      :param preds: the predictions to convert
      :type preds: list
      :return: the predictions, None if no predictions present
      :rtype: Instances