Regression

In this unit you fit your first models. We use tidymodels, a set of R packages for fitting models the tidyverse way. The lecture is a notebook. You pull it into your fork, install tidymodels, and live code it with me in class. At the end you push the finished notebook and turn in the link.

You need your fork of the class repo and the pixi environment from the Codespaces unit.

1. Sync your fork

The lecture notebook is in the class repo, not in your fork yet. To sync is to pull new commits from the class repo into your copy.

  1. Open your fork on GitHub. The address looks like github.com/YOUR-USERNAME/codespace.
  2. Near the green Code button, click Sync fork.
  3. Click Update branch.

If GitHub offers to discard your commits instead, stop and ask the instructor. Do not click it.

2. Pull into your Codespace

Your Codespace does not know about the new commit yet. Open it from github.com/codespaces. In the terminal:

git pull

Check that the notebook arrived:

ls notebooks

You should see 08-lecture-regression.ipynb.

3. Install tidymodels

Add it to your pixi environment:

pixi add r-tidymodels

This pulls in many packages. It can take a minute or two. Wait for the prompt to come back.

If it fails, run pixi install, then try pixi add r-tidymodels again. If it still fails, tell the instructor.

4. Start JupyterLab

pixi shell
jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --IdentityProvider.token='' --ServerApp.password='' --config=jupyter_config.py

Open JupyterLab the same way as before. Click the Ports tab, find the 8888 row, and click the globe icon. Do not use the Open in Browser popup.

The Ports tab in VS Code. The row for port 8888 is highlighted and the globe icon shows a tooltip that says Open in Browser.

Hover over the 8888 row and click the globe.

5. Complete the notebook

We will do this together in class. In JupyterLab, double-click the notebooks folder, then 08-lecture-regression.ipynb. We live code each cell as we go.

6. Commit and push

Save the notebook with Ctrl+S. Then go to the VS Code tab:

  1. Click the Source Control icon on the left bar.
  2. Stage these files by clicking the + next to each one:
    • notebooks/08-lecture-regression.ipynb
    • pixi.toml
    • pixi.lock
  3. Type a message like add regression lecture.
  4. Click Commit.
  5. Click the … menu at the top of the Source Control panel and choose Push.

7. Turn it in

  1. Open your fork on GitHub and refresh.
  2. Click the notebooks folder, then click 08-lecture-regression.ipynb.
  3. Copy the address. It looks like https://github.com/YOUR-USERNAME/codespace/blob/main/notebooks/08-lecture-regression.ipynb.
  4. Paste it into the Canvas assignment.

GitHub shows the notebook with its outputs. Check that the outputs are there. The notebook is your turn-in for this unit.

Things to know

  • Stop your Codespace when you are done to save your free hours.
  • Next time you open the Codespace, tidymodels is still there. Run pixi shell and the JupyterLab command again.