title: Apache Spark MLlib - getting LabeledPoint from data (Java)
body: <p>I am new to Apache Spark and was trying to convert data from .csv file into LabeledPoint to use MLlib package of Apache Spark. I tried the following code to get the LabeledPoint Data RDD using the following code but it turns out it was a LabeledPoint Data of ML Package. Now I want to get create the correct LabeledPoint Data of MLlib Package. Could anyone please help.</p>
  
  <pre><code>private static String appName = "learning_RDD";
  private static String master = "spark://23.195.26.187:7077" ;
  static SparkConf sparkConf = new SparkConf().setMaster("local[1]").setAppName("MLPipelineSample").set("spark.driver.memory", "512m").set("spark.sql.warehouse.dir","D:\\input.txt");
  static SparkContext sc = new SparkContext(sparkConf);
  static SparkSession spark = SparkSession
            .builder().sparkContext(sc)
            .getOrCreate();
  
  public static void main(String args[]) throws IOException {
  
      Dataset&lt;Row&gt; trainingData = spark.read().format("com.databricks.spark.csv").option("header", "true").option("inferSchema", "true").load("D:\\abc\\Spark\\WebcontentClassification_UsingSparkML\\WebcontentClassification_UsingSparkML\\NaiveBayes_ML_20ErrorRate\\nutchcsvalldata.csv");
  
      Tokenizer tokenizer = new Tokenizer().setInputCol("content").setOutputCol("words");
      Dataset&lt;Row&gt; words = tokenizer.transform(trainingData);
  
      StopWordsRemover remover = new StopWordsRemover().setInputCol("words").setOutputCol("filteredwords");
      Dataset&lt;Row&gt; filteredwords = remover.transform(words);
  
      HashingTF hashingTF = new HashingTF().setNumFeatures(1000).setInputCol("filteredwords").setOutputCol("rawfeatures");
      Dataset&lt;Row&gt; hashedtf_Vector = hashingTF.transform(filteredwords);
  
      IDF idf = new IDF().setInputCol("rawfeatures").setOutputCol("features");
      IDFModel idfModel = idf.fit(hashedtf_Vector);
      Dataset&lt;Row&gt; Vectors = idfModel.transform(hashedtf_Vector);             
  
      Iterator&lt;Row&gt; iterator = Vectors.toLocalIterator();
      List&lt;LabeledPointLabeledPoint&gt; labeledpoints = new ArrayList&lt;LabeledPoint&gt;();
      while(iterator.hasNext())
      {
          Row r = iterator.next();
          int label = r.getAs(2);
          Vector v = r.getAs(16);
          LabeledPoint labeledpoint = new LabeledPoint(label, v);
          labeledpoints.add(labeledpoints);
      }
  
          // Here I am suppose convert the List into RDD&lt;LabeledPoint&gt; and use                           SVM Algorithm
  }
  </code></pre>