EE104: Introduction to Machine Learning

Stanford University, Spring Quarter 2018

In this course, you will use the Julia language to create short scripts for the assignments.


We highly recommend that you use JuliaBox to implement the Julia scripts for the assignments in this course. JuliaBox allows you to create Julia ‘notebooks’, which are interactive coding environments that run in the browser. They will work immediately with no installation on your machine required.

Important features in Julia

You are welcome to ask questions about Julia on Piazza and in office hours. Below, we have collected some Julia tricks and tips that you might need.

  • Installing a Julia package (JuliaBox). Since the Pkg.add(…) command does not work in JuliaBox, you will instead add a package through the Packages tab on the home screen of JuliaBox. This will open a window called Package Builder. Under the “Yours” tab, type the name of the package you want to install in the first box, and click the “+” symbol. Then scroll to the bottom and click Start.

  • Installing a Julia package (local installation). To install a Julia package, you simply use Pkg.add(…). For example, to install the data formatting library JSON you issue the command Pkg.add(“JSON”). Yes, the quotes are necessary.

  • Using a Julia package. Once you are sure that a package has been installed, you can use a package in Julia script or notebook with the using command. For example, to use the JSON library, you issue the command using JSON.

  • Including helper code. For many assignments, we will give you helper code in the form of a Julia (.jl) file. To use this code in your scripts and notebook, use the include(“filename.jl”) command. It is always helpful to read the provided Julia file, as we will often include helpful comments about the usage of our pre-defined functions.

Reading JSON files

In order to read the JSON format we will use in this class, you need the readclassjson.jl script, which contains the readclassjson(filename) method. This method returns a dictionary containing all of the variables defined in the file.
So, if the example_file.json contains a variable called X, you can read it by using


data = readclassjson("example_file.json")
X = data["X"]

Julia references

The following links are tutorials and references that will help you with Julia. Some are taken from EE103. To run .ipynb files, first download the code by right-clicking “code” and clicking “Save link as…”. Then, upload the file to JuliaBox with the “upload” button under the “Jupyter” tab.