class_docstr: The Ensemble class can be used to create ensembles of stellargraph's graph neural network algorithms including
  GCN, GraphSAGE, GAT, and HinSAGE. Ensembles can be used for training classification and regression problems for
  node attribute inference and link prediction.
  
  The Ensemble class can be used to create Naive ensembles.
  
  Naive ensembles add model diversity by random initialisation of the models' weights (before training) to
  different values. Each model in the ensemble is trained on the same training set of examples.
  
  .. seealso::
  
     Example using ensembles: `node classification <https://stellargraph.readthedocs.io/en/stable/demos/ensembles/ensemble-node-classification-example.html>`__.
  
     Related functionality: :class:`.BaggingEnsemble` for bootstrap sampling while training, in addition to random initialisation.
class_docstr_tok: ["The","Ensemble","class","can","be","used","to","create","ensembles","of","stellargraph","'s","graph","neural","network","algorithms","including","GCN",",","GraphSAGE",",","GAT",",","and","HinSAGE",".","Ensembles","can","be","used","for","training","classification","and","regression","problems","for","node","attribute","inference","and","link","prediction",".","The","Ensemble","class","can","be","used","to","create","Naive","ensembles",".","Naive","ensembles","add","model","diversity","by","random","initialisation","of","the","models","'","weights","(","before","training",")","to","different","values",".","Each","model","in","the","ensemble","is","trained","on","the","same","training","set","of","examples",".","..","seealso",":",":","Example","using","ensembles",":","`","node","classification","<","https",":","\/\/stellargraph.readthedocs.io\/en\/stable\/demos\/ensembles\/ensemble-node-classification-example.html",">","`","__",".","Related","functionality",":",":","class",":","`",".BaggingEnsemble","`","for","bootstrap","sampling","while","training",",","in","addition","to","random","initialisation","."]
docstr: This method generates predictions for the data produced by the given generator or alternatively the data
  given in parameter predict_data.
  
  For detailed descriptions of Keras-specific parameters consult the Keras documentation
  at https://keras.io/models/sequential/
  
  Args:
      generator: The generator object that, if predict_data is None, should be one of type
          GraphSAGENodeGenerator, HinSAGENodeGenerator, FullBatchNodeGenerator, GraphSAGELinkGenerator,
          or HinSAGELinkGenerator. However, if predict_data is not None, then generator should be one of type
          NodeSequence, LinkSequence, SparseFullBatchSequence, or FullBatchSequence.
      predict_data (None or iterable): If not None, then it is an iterable, e.g. list, that specifies the node IDs
          to make predictions for. If generator is of type FullBatchNodeGenerator then predict_data should be all
          the nodes in the graph since full batch approaches such as GCN and GAT can only be used to make
          predictions for all graph nodes.
      summarise (bool): If True, then the mean of the predictions over self.n_estimators and
          self.n_predictions are returned for each query point. If False, then all predictions are returned.
      output_layer (None or int): If not None, then the predictions are the outputs of the layer specified.
          The default is the model's output layer.
      max_queue_size (int): (Keras-specific parameter) The maximum size for the generator queue.
      workers (int): (Keras-specific parameter) The maximum number of workers to use.
      use_multiprocessing (bool): (Keras-specific parameter) If True then use process based threading.
      verbose (int): (Keras-specific parameter) The verbosity mode that should be 0 or 1 with the former turning
          verbosity off and the latter on.
  
  
  Returns:
      numpy array: The predictions. It will have shape ``M × K × N × F`` if ``summarise`` is set to ``False``, or ``N × F``
      otherwise. ``M`` is the number of estimators in the ensemble; ``K`` is the number of predictions per query
      point; ``N`` is the number of query points; and ``F`` is the output dimensionality of the specified layer
      determined by the shape of the output layer.
docstr_tok: ["This","method","generates","predictions","for","the","data","produced","by","the","given","generator","or","alternatively","the","data","given","in","parameter","predict_data",".","For","detailed","descriptions","of","Keras-specific","parameters","consult","the","Keras","documentation","at","https",":","\/\/keras.io\/models\/sequential\/","Args",":","generator",":","The","generator","object","that",",","if","predict_data","is","None",",","should","be","one","of","type","GraphSAGENodeGenerator",",","HinSAGENodeGenerator",",","FullBatchNodeGenerator",",","GraphSAGELinkGenerator",",","or","HinSAGELinkGenerator",".","However",",","if","predict_data","is","not","None",",","then","generator","should","be","one","of","type","NodeSequence",",","LinkSequence",",","SparseFullBatchSequence",",","or","FullBatchSequence",".","predict_data","(","None","or","iterable",")",":","If","not","None",",","then","it","is","an","iterable",",","e.g",".","list",",","that","specifies","the","node","IDs","to","make","predictions","for",".","If","generator","is","of","type","FullBatchNodeGenerator","then","predict_data","should","be","all","the","nodes","in","the","graph","since","full","batch","approaches","such","as","GCN","and","GAT","can","only","be","used","to","make","predictions","for","all","graph","nodes",".","summarise","(","bool",")",":","If","True",",","then","the","mean","of","the","predictions","over","self.n_estimators","and","self.n_predictions","are","returned","for","each","query","point",".","If","False",",","then","all","predictions","are","returned",".","output_layer","(","None","or","int",")",":","If","not","None",",","then","the","predictions","are","the","outputs","of","the","layer","specified",".","The","default","is","the","model","'s","output","layer",".","max_queue_size","(","int",")",":","(","Keras-specific","parameter",")","The","maximum","size","for","the","generator","queue",".","workers","(","int",")",":","(","Keras-specific","parameter",")","The","maximum","number","of","workers","to","use",".","use_multiprocessing","(","bool",")",":","(","Keras-specific","parameter",")","If","True","then","use","process","based","threading",".","verbose","(","int",")",":","(","Keras-specific","parameter",")","The","verbosity","mode","that","should","be","0","or","1","with","the","former","turning","verbosity","off","and","the","latter","on",".","Returns",":","numpy","array",":","The","predictions",".","It","will","have","shape","``","M","\u00d7","K","\u00d7","N","\u00d7","F","``","if","``","summarise","``","is","set","to","``","False","``",",","or","``","N","\u00d7","F","``","otherwise",".","``","M","``","is","the","number","of","estimators","in","the","ensemble",";","``","K","``","is","the","number","of","predictions","per","query","point",";","``","N","``","is","the","number","of","query","points",";","and","``","F","``","is","the","output","dimensionality","of","the","specified","layer","determined","by","the","shape","of","the","output","layer","."]
code: def predict(
      self,
      generator,
      predict_data=None,
      summarise=False,
      output_layer=None,
      max_queue_size=10,
      workers=1,
      use_multiprocessing=False,
      verbose=0,
  ):
      """
      This method generates predictions for the data produced by the given generator or alternatively the data
      given in parameter predict_data.
  
      For detailed descriptions of Keras-specific parameters consult the Keras documentation
      at https://keras.io/models/sequential/
  
      Args:
          generator: The generator object that, if predict_data is None, should be one of type
              GraphSAGENodeGenerator, HinSAGENodeGenerator, FullBatchNodeGenerator, GraphSAGELinkGenerator,
              or HinSAGELinkGenerator. However, if predict_data is not None, then generator should be one of type
              NodeSequence, LinkSequence, SparseFullBatchSequence, or FullBatchSequence.
          predict_data (None or iterable): If not None, then it is an iterable, e.g. list, that specifies the node IDs
              to make predictions for. If generator is of type FullBatchNodeGenerator then predict_data should be all
              the nodes in the graph since full batch approaches such as GCN and GAT can only be used to make
              predictions for all graph nodes.
          summarise (bool): If True, then the mean of the predictions over self.n_estimators and
              self.n_predictions are returned for each query point. If False, then all predictions are returned.
          output_layer (None or int): If not None, then the predictions are the outputs of the layer specified.
              The default is the model's output layer.
          max_queue_size (int): (Keras-specific parameter) The maximum size for the generator queue.
          workers (int): (Keras-specific parameter) The maximum number of workers to use.
          use_multiprocessing (bool): (Keras-specific parameter) If True then use process based threading.
          verbose (int): (Keras-specific parameter) The verbosity mode that should be 0 or 1 with the former turning
              verbosity off and the latter on.
  
  
      Returns:
          numpy array: The predictions. It will have shape ``M × K × N × F`` if ``summarise`` is set to ``False``, or ``N × F``
          otherwise. ``M`` is the number of estimators in the ensemble; ``K`` is the number of predictions per query
          point; ``N`` is the number of query points; and ``F`` is the output dimensionality of the specified layer
          determined by the shape of the output layer.
  
      """
      data_generator = generator
      if predict_data is not None:
          if not isinstance(
              generator,
              (
                  sg.mapper.GraphSAGENodeGenerator,
                  sg.mapper.HinSAGENodeGenerator,
                  sg.mapper.FullBatchNodeGenerator,
              ),
          ):
              raise ValueError(
                  "({}) generator parameter must be of type GraphSAGENodeGenerator, HinSAGENodeGenerator, or FullBatchNodeGenerator. Received type {}".format(
                      type(self).__name__, type(generator).__name__
                  )
              )
          data_generator = generator.flow(predict_data)
      elif not isinstance(
          generator,
          (
              sg.mapper.NodeSequence,
              sg.mapper.LinkSequence,
              sg.mapper.FullBatchSequence,
              sg.mapper.SparseFullBatchSequence,
          ),
      ):
          raise ValueError(
              "({}) If x is None, generator must be one of type NodeSequence, "
              "LinkSequence, SparseFullBatchSequence, or FullBatchSequence.".format(
                  type(self).__name__
              )
          )
  
      predictions = []
  
      if output_layer is not None:
          predict_models = [
              K.Model(
                  inputs=model.input,
                  outputs=model.layers[output_layer].output,
              )
              for model in self.models
          ]
      else:
          predict_models = self.models
  
      for model in predict_models:
          model_predictions = []
          for _ in range(self.n_predictions):
              model_predictions.append(
                  model.predict(
                      data_generator,
                      max_queue_size=max_queue_size,
                      workers=workers,
                      use_multiprocessing=use_multiprocessing,
                      verbose=verbose,
                  )
              )
          # add to predictions list
          predictions.append(model_predictions)
  
      predictions = np.array(predictions)
  
      if summarise is True:
          # average the predictions across models and predictions per query point
          predictions = np.mean(predictions, axis=(0, 1))
  
      # if len(predictions.shape) > 4:
      #     predictions = predictions.reshape(predictions.shape[0:3] + (-1,))
  
      return predictions
  
imports: from stellargraph.layer import *
  import numpy
  from tensorflow import keras
  from tensorflow.keras.callbacks import EarlyStopping
  import stellargraph
label_desc: Use image node_id 9 for calling the Ensemble obj's underlying member method code with example usage: obj.predict(generator, predict_data, summarise, output_layer, max_queue_size, workers, use_multiprocessing, verbose) and returns: predictions