code: def lp_to_simple_rdd(lp_rdd, categorical=False, nb_classes=None):
      
      if categorical:
          if not nb_classes:
              labels = np.asarray(lp_rdd.map(
                  lambda lp: lp.label).collect(), dtype='int32')
              nb_classes = np.max(labels) + 1
          rdd = lp_rdd.map(lambda lp: (from_vector(lp.features),
                                       encode_label(lp.label, nb_classes)))
      else:
          rdd = lp_rdd.map(lambda lp: (from_vector(lp.features), lp.label))
      return rdd
docs: Convert a LabeledPoint RDD into an RDD of feature-label pairs
  
      :param lp_rdd: LabeledPoint RDD of features and labels
      :param categorical: boolean, if labels should be one-hot encode when returned
      :param nb_classes: int, number of total classes
      :return: Spark RDD with feature-label pairs