O'Reilly logo

Learning Jupyter by Dan Toomey

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

Scala data access in Jupyter

There is a copy of the iris dataset on the University of California, Irvine website at https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data . We will access this data and perform some simpler statistics on the same.

The Scala code is as follows:

import scala.io.Source;
//copied file locally https://archive.ics.uci.edu/ml/
      machine-learning-databases/iris/iris.data
val filename = "iris.data"

//DEBUGGING Uncomment this line to display more information -
println("SepalLength, SepalWidth, PetalLength, PetalWidth, Class");
val array = scala.collection.mutable.ArrayBuffer.empty[Float]
for (line <- Source.fromFile(filename).getLines) {
    var cols = line.split(",").map(_.trim);
 //println(s"${cols(0)}|${cols(1)}|${cols(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