O'Reilly logo

Machine Learning with Spark - Second Edition by Nick Pentreath, Manpreet Singh Ghotra, Rajdeep Dua

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Visualizing the StumbleUpon dataset

We ran custom logic to reduce the number of features to two, so that we can visualize the dataset in a two-dimensional plane, keeping the lines in the dataset constant.

{  val sc = new SparkContext("local[1]", "Classification")   // get StumbleUpon dataset 'https://www.kaggle.com/c/stumbleupon'   val records = sc.textFile(    SparkConstants.PATH + "data/train_noheader.tsv").map(    line => line.split("\t"))   val data_persistent = records.map { r =>     val trimmed = r.map(_.replaceAll("\"", ""))     val label = trimmed(r.size - 1).toInt     val features = trimmed.slice(4, r.size - 1).map(      d => if (d == "?") 0.0 else d.toDouble)     val len = features.size.toInt     val len_2 = math.floor(len/2).toInt  val x = features.slice(0,len_2) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required