BIOS 512: Data Science Basics

👋 Welcome to the Data Science Basics course!

The primary text for this course is Hello Data Science: A friendly introduction with applications. Although we will diverge from the text to explore concepts in statistical modeling and inference.

Lectures

Hello World

Lecture

Course intro and your first line of code. Launch lecture notebook in JupyterLite


Exercise

Plot penguins with ggplot2, then break the code on purpose. Launch exercise notebook in JupyterLite

Data Visualization

Lecture

Visualize survey data with ggplot2, one variable at a time. Launch lecture notebook in JupyterLite


Exercise: Distributions

Histograms and density plots of diamond prices. Launch exercise notebook in JupyterLite


Exercise: Geoms

Bar charts and line charts with ggplot2. Launch exercise notebook in JupyterLite

Scales and Theme

Lecture

How scales map data to color, position, and size. Launch lecture notebook in JupyterLite


Exercise: Color Brewer

Color a correlation heatmap with ColorBrewer palettes. Launch exercise notebook in JupyterLite


Exercise: Scales

Fix a skewed salary histogram with a log scale. Launch exercise notebook in JupyterLite

Data Wrangling

Lecture

Build ECDF charts and transform data with dplyr. Launch lecture notebook in JupyterLite


Exercise: ECDF Turn in

Compare income before and after 1995 with histograms and an ECDF chart. Launch exercise notebook in JupyterLite


Exercise: Slicing

Find the fastest Boston Marathon winners by group with slice_min. Launch exercise notebook in JupyterLite

Data Types

Lecture

Work with strings, dates, and factors. Launch lecture notebook in JupyterLite


Exercise: Forcats Turn in

Chart NYC 311 complaint categories and lump low-frequency values with forcats. Launch exercise notebook in JupyterLite

Joining and Pivoting

Lecture

Combine tables with joins and reshape data with pivot_longer and pivot_wider. Launch lecture notebook in JupyterLite


Exercise: Joins

Find the saddest Friend by joining lines with emotions and charting the counts. Launch exercise notebook in JupyterLite


Exercise: Pivoting Turn in

Pivot the Billboard chart data to rank songs by how many weeks they spent in the Top 10. Launch exercise notebook in JupyterLite


Exercise: Marathon Vis

Reproduce a FiveThirtyEight chart of marathon winning times. Launch exercise notebook in JupyterLite


Exercise: Pivot Wider Turn in

Use pivot_wider to put men’s and women’s marathon times side by side. Launch exercise notebook in JupyterLite

Codespaces

Lecture

Fork the class repo, open it in a GitHub Codespace, and build your own R environment with pixi. Read the step-by-step guide.


Exercise: GitHub Account Turn in

Create a free GitHub account. You need one to fork the repo and open a Codespace.


Exercise: Hello World Turn in

Fork the class repo, add a hello world notebook, and turn in the link to your fork. Fork the class repo on GitHub

AI Pairing

Lecture

Get a key from the class LLM gateway, connect opencode to JupyterLab with MCP, and build a model together. Read the step-by-step guide.


Exercise: Gateway Key

Get a gateway key and add it to your Codespace as a secret. Get a key from the class LLM gateway

Regression

Lecture

Sync the lecture notebook into your fork, install tidymodels, and fit linear regression models to GSS survey data. Read the step-by-step guide.


Exercise: Regression Notebook Turn in

Live code in class, push, and turn in the link to your notebook. View the regression lecture notebook on GitHub

Model Basics

Lecture

Find out where model parameters come from. Guess lines, measure their distance from the data, and let optim() search for the best one. Read the step-by-step guide.


Exercise: Model Basics Notebook

Live code in class and push to your fork. No turn-in. View the model basics solution notebook on GitHub

Marginal Effects

Lecture

How much does the outcome change when a predictor moves by one unit? Calculate marginal effects from a straight line, from a curve where the answer depends on the value of the predictor, and from a model of log income. Read the step-by-step guide.


Exercise: Education and Marijuana Turn in

Use the same recipe on a yes/no outcome with your AI assistant. Push it with the submit prompt, and turn in the link.

Logistic Regression

Lecture

Model a yes/no outcome. See why a straight line fails, wrap it in the inverse logit, search for the parameters with optim(), then fit the same model with logistic_reg(). Read the step-by-step guide.


Exercise: The Challenger Launch Turn in

Model O-ring damage against launch temperature with your AI assistant. Push it with the submit prompt, and turn in the link.

Multiple Regression

Lecture

Put more than one predictor in a model. Add curves for age and education, plot the predictions, and find the average marginal effect of education. Read the step-by-step guide.


Exercise: Doctor Who on Holidays Turn in

Do holiday episodes get more viewers? Find out with your AI assistant. Push it with the submit prompt, and turn in the link.

Random Forests

Lecture

Draw the decision boundary of a model. See why logistic regression draws a straight line, then fit a decision tree and a random forest that can follow other shapes. Install ranger and rpart.plot with pixi. Read the step-by-step guide.


Exercise: EDM or Rap? Turn in

Can a model tell an EDM song from a rap song by its tempo? Find out with your AI assistant. Push it with the submit prompt, and turn in the link.

Dengue Forecasting

Lecture

Forecast weekly dengue cases in two cities with a random forest. Add lag features and see which ones matter most. Install vip with pixi and upload the data from Canvas. Read the step-by-step guide.


Exercise: Dengue Forecasting Turn in

Does last week’s weather help predict this week’s cases? Find out with your AI assistant. Push it with the submit prompt, and turn in the link.

Penguin Forest

Lecture

Predict penguin bill length with a random forest, and see which features matter most. Copy the notebooks into your fork with a prompt and install palmerpenguins with pixi. Read the step-by-step guide.


Exercise: Hotel Bookings Turn in

Which hotel stays include children? Fit a decision tree and a random forest with your AI assistant. Push it with the submit prompt, and turn in the link.

Neural Networks

Lecture

See that a neural network is many small logistic regressions added up. Add more nodes and watch the model bend, then overfit. Install nnet with pixi. Read the step-by-step guide.


Exercise: How Many Nodes? Turn in

Can a neural network tell EDM from rap? Do more nodes help? Find out with your AI assistant. Push it with the submit prompt, and turn in the link.

Encoders

Lecture

Use a trained neural network to turn photos into rows of numbers. Then fit a regular model on that table. Install embed and glmnet with pixi. Read the step-by-step guide.


Exercise: Find Malaria Turn in

Can an encoder tell infected blood cells from healthy ones? Plot the cells with UMAP and fit a model with your AI assistant. Push it with the submit prompt, and turn in the link.

CLIP

Lecture

Look inside CLIP, an encoder that turns photos and sentences into numbers. Then use it to encode blood cell photos. Step through two marimo notebooks in molab. Read the step-by-step guide.


Exercise: Name the Blood Cell Turn in

Can a model name 8 types of blood cell from CLIP embeddings? Plot them with UMAP and fit a random forest with your AI assistant. Push it with the submit prompt, and turn in the link.

marimo

Lecture

A short, fun look at marimo, a notebook tool for Python. Set up your Codespace to run it, then try it with me in class. Read the step-by-step guide.

AI Interpretability

Lecture

Look inside a neural network. See how it packs many ideas into a few neurons, then pull them apart with a sparse autoencoder. Step through two marimo notebooks in molab. Read the step-by-step guide.


Exercise: Did the SAE Find the True Features?

The SAE never saw the answer key. Peek at it and check whether the SAE found the 5 true features.