class_docstr: Synchronous Spark worker. This code will be executed on workers.
      
docstr: Train a keras model on a worker
          
docstr_tok: ["Train","a","keras","model","on","a","worker"]
code: def train(self, data_iterator):
      """Train a keras model on a worker"""
      history = None
      optimizer = get_optimizer(self.master_optimizer)
      self.model = model_from_json(self.json, self.custom_objects)
      self.model.compile(
          optimizer=optimizer,
          loss=self.master_loss,
          metrics=self.master_metrics,
      )
      self.model.set_weights(self.parameters.value)
  
      feature_iterator, label_iterator = tee(data_iterator, 2)
      x_train = np.asarray([x for x, y in feature_iterator])
      y_train = np.asarray([y for x, y in label_iterator])
  
      weights_before_training = self.model.get_weights()
      if x_train.shape[0] > self.train_config.get("batch_size"):
          history = self.model.fit(
              x_train, y_train, **self.train_config
          )
      weights_after_training = self.model.get_weights()
      deltas = subtract_params(
          weights_before_training, weights_after_training
      )
      if history:
          yield [deltas, history.history]
      else:
          yield [deltas, None]
  
file_path: elephas/elephas/worker.py
imports: import numpy
  from itertools import tee
  from tensorflow.keras.models import model_from_json
  from tensorflow.keras.optimizers import get
  from tensorflow.python.keras.utils.generic_utils import slice_arrays
  from .utils import subtract_params
  from .parameter import BaseParameterClient
label_desc: Use image node_id 2 for calling the SparkWorker obj's underlying member method code with example usage: obj.train(data_iterator) without return types