JupyterLab data science lab: pandas, Matplotlib and scikit-learn in the browser

This lab gives each student a JupyterLab of their own, with the Python data science libraries already in it: pandas for tables, NumPy for numbers, Matplotlib for charts and scikit-learn for models. The work folder holds a year of made-up bike hire records, one row a day with the weather, and a starter notebook that loads, summarises, draws and models them.

It is not an attack lab. Every copy has no route to the internet and none to any other student, so nothing can be downloaded into it and nothing in it can reach anybody else.

What students learn

How a CSV file becomes a DataFrame with pandas, and how describe and groupby sum up a column and compare groups: sunny days have the most hires, rainy days the fewest. Then a scatter chart in Matplotlib that shows warmer days are busier, and a first linear regression in scikit-learn that turns that pattern into a rule, with R squared to say how much of the change it explains. Along the way they work in a notebook, one cell at a time, the way data scientists do. It suits introductions to data science, statistics with code and machine learning; check your own awarding body’s unit for the exact wording, none is quoted here.

Run it in your browser

The lab starts one service, jupyter, which writes the data, the notebook and the short scripts into its work folder and is ready in a few seconds. It uses about 75 MB when idle and about 235 MB with a notebook running, inside the 512 MB a service may have. JupyterLab asks for no token, because the platform’s own door already knows who is opening it. The terminal beside the lab has no Python of its own, so it reaches the lab’s with docker exec jupyter, followed by the command to run inside.

  1. Open the Container page. Open Build on the bar and choose Run a container. Anybody may open it, and the Git lab and the SQL lab start with no account. Every other lab needs a free account: create one, sign in, then press Start.
  2. Find the lab. The Sample labs card lists every sample. Find JupyterLab: data science with pandas.
  3. Press Start. Start runs it as it is, in one press. Edit the file first opens the compose file so you can change it before you start.
  4. Open it. On the lab’s page, the lab bar has a link called JupyterLab: press it to open JupyterLab in your browser and double-click start.ipynb. Then press Open terminal and type docker exec jupyter python3 steps/load.py to see the size of the data, 365 rows and 7 columns, and its first five rows.

What to ask students to hand in

A notebook of their own over hires.csv that answers one question they chose, such as which weather is busiest at the weekend, which month is quietest, or whether a model does better when it knows the weekday, downloaded from JupyterLab with File, Download. Then a sentence or two in their own words on what the data showed and what it does not prove. Nothing is marked automatically: the sentence shows whether it was understood. For stronger work ask for a chart that supports the answer and a model compared with a simpler one.

A basic lesson on this lab

JupyterLab Basics is a small lesson worked in this lab. In it a student lists the work folder, loads the data with pandas, summarises the hires and compares them by weather, saves a chart, fits a linear regression, and then opens the same work in the starter notebook.

Free personal accounts have it in the Basics module, which is on Home, every college can copy it from the Library’s Basics folder, and a new college opens with it in a module called Data Labs (Sample). It is deliberately small: it shows a teacher what a lesson worked in a lab is, and the lab does the rest. Copy it into a module of your own to change it.

The code on GitHub

The compose file has no Dockerfile: it runs one stock public image, the Jupyter Docker Stacks’ own scipy-notebook, pinned to a dated tag, as its own unprivileged account with 512 MB of memory. The image is licensed BSD-3-Clause and is not distributed by us. The file writes the data from a fixed seed when it starts, so every copy has the same numbers and nothing is downloaded. The limits are honest ones: the data is made up and small, there is no GPU, nothing can be installed from the internet, and a model that needs far more memory than the copy has will fail. Nothing is kept when the lab stops, so a student downloads their notebook first.

Set it as work

Say in the task what to hand in.

  1. Make the lab. In your module add a task and choose the Container lab card, then In a GitHub repository. Give https://github.com/mitsurutech/lab-jupyter-data with the branch main. The compose file is the default, compose.yaml. Fork the repository first if you want to change it, for example to write a different data set.
  2. Publish and try it. Publish pins the commit you were shown, so a later change in the repository does not alter a lab you have already set. Start your own copy first.
  3. Hand it out. Assign it like any task, with a due date if you want one, and say in the task what to do and what to hand in.
  4. Mark what is handed in. Open a student’s copy and the work they handed in, mark it, and send it back with a reason if it needs more.

Questions people ask

Why is there no token or password to type?
A lab’s web page is reached only through the platform’s own door, which already knows who you are and lets in only you and the staff who teach your module. So JupyterLab is started with no token. Do not run it like that on a machine anybody else can reach.
Why does the terminal use docker exec jupyter?
The lab’s terminal carries curl, psql and a few other clients, and no Python. docker exec jupyter runs a command inside the lab’s own container, which has Python and every library. JupyterLab also has a terminal of its own, under File, New, Terminal.
Can students install more packages or use their own data?
Not from the internet, which a copy cannot reach, so the libraries are the ones in the image. For other data, fork the repository, change the rows the compose file writes, and set the fork as the lab.