May 2018
Beginner to intermediate
384 pages
10h 19m
English
The following code represents how to perform text classification using the NB algorithm:
import org.apache.spark.ml.{Pipeline, PipelineModel}import org.apache.spark.ml.classification.{NaiveBayes, NaiveBayesModel}import org.apache.spark.ml.feature.{StringIndexer, StopWordsRemover, HashingTF, Tokenizer, IDF, NGram}import org.apache.spark.ml.linalg.Vectorimport org.apache.spark.sql.Row//Sample Dataval exampleDF = spark.createDataFrame(Seq((1,"Samsung 80 cm 32 inches FH4003 HD Ready LED TV"),(2,"Polaroid LEDP040A Full HD 99 cm LED TV Black"),(3,"Samsung UA24K4100ARLXL 59 cm 24 inches HD Ready LED TV Black"))).toDF("id","description")exampleDF.show(false)//Add labels to datasetval indexer = new StringIndexer() ...Read now
Unlock full access