EE104/CME107: Introduction to Machine Learning

Stanford University, Spring Quarter, 2024

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

Julia

We highly recommend that you install Julia natively on your own machine.

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

  • Installing a Julia package. To install a Julia package, you use Pkg.add. For example, to install the data formatting library JSON you issue the command Pkg.add(“JSON”).

  • 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

include("readclassjson.jl")

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

Julia references

The following links are tutorials and references that will help you with Julia.