Cultural Data Analysis · Week 3: Structured Data and Machine Learning
This week's workshop has two parts: a 30-minute data critique in groups, and the machine learning workshop with clustering and decision trees.
First: save your own copy. Unless the notebook is already in your own Google Drive, Colab does not keep your changes. Go to File → Save a copy in Drive and work in the copy that opens in a new tab. You find it later in Google Drive, in Colab Notebooks.
Every dataset was made by someone, for some purpose, about some people. This week is about structured data: tables of rows and columns, as in a spreadsheet or a database. Before we analyse such a table, and before a machine learns from it, we ask what it is, who made it, who is in it and who is left out, and what happens when its columns become a label (what a model predicts) and features (what it predicts from).
Use the ten questions below on every table of data you work with: the Senate votes and Spotify songs in the next hour, and the tables in your group project. Today we practise them on one case, the donation records of a (fictional) NGO. The questions also help with text corpora, though some will need adapting.
Mostly thinking, not coding. Most questions are answered by reading the data sheet, looking at the rows and discussing. For each answer, say what it rests on: the data sheet says …, we saw in the data …, or we assume …. Code is there if you want to check a suspicion.
| Minutes | What |
|---|---|
| 0–5 | Read the case and the data sheet below; look at the first rows of the data |
| 5–20 | In your group, work through the ten questions. Write a sentence or two per question in the data critique template (below) |
| 20–30 | All together: each group brings its strongest point, then question 10: can this data answer the NGO's question? |
Write your answers in the data critique template, a Markdown file with the ten questions, room for your answers, and after each answer what it rests on. It is a short version of Datasheets for Datasets (Gebru et al.). Download it, fill it in for today's case, and use a copy for every table in your group project.
The right-hand column says where to look in today's case.
| # | Question (for any table of data) | In the donor case, look at … |
|---|---|---|
| The data: where it comes from | ||
| 1 | Who made this data, for what purpose, and with what system or process? Whose question was it made to answer? | Who wrote the data sheet, and what do they want from the data? |
| 2 | What does one row stand for, and what is outside the data: which people, periods or cases, and why? | The export filter, and the three ways gifts come in. |
| 3 | Which categories did someone design (gender, region, age bands …)? What can't be said in them? | The columns gender, age_range, region and campaign. |
| 4 | What looks missing, wrong or inconsistent? Is it a mistake, or a trace of how the data was made? | The dates and campaigns, the age and gender of cheque donors, and what a donor ID really identifies. |
| The label: what a model would predict | ||
| 5 | What would the label be for the question being asked? Who defines it, and is it a proxy for what we actually care about? | There is no "retention" column. How would you make one, and what would it count as a loyal donor? |
| 6 | Where do the features come from: measured, chosen by the people themselves, typed in by someone else, or computed by another system? | Who filled in each column, and on which channel? |
| The people: who is in it and who is affected | ||
| 7 | Who are the people in the data? Did they know, did they agree, and did they agree to this use? | The last line of the data sheet, and what "donor retention" means for the donors. |
| 8 | Which attributes are personal or sensitive, or could reveal something sensitive in combination? Could someone be identified? | Names, and what name, region, age band and a gift to a particular appeal say together. |
| 9 | Who could benefit, and who could be harmed or left out, if the analysis is used? | Donors who give little, or by cheque; and the people the NGO is supposed to help. |
| Together | ||
| 10 | Can this data answer the question at all? What would you need to know, or whom would you need to ask, before trusting it? | The NGO's question: understand donation patterns, improve fundraising, keep donors. |
A disaster relief NGO, Global Aid Alliance, has exported five years of donation records. It wants to understand donation patterns, improve fundraising efficiency and increase donor retention: keeping donors giving. Can the data do this, and should it be used this way?
Global Aid Alliance is a fictional organisation; the data are made up for teaching. Read the data sheet as if it were real: it is the organisation's own account of its data, and like any such account it may be incomplete or wrong.
The notebook loads donor_records_export.csv and helps you test what you write about the label and the features: it makes a label in three ways, shows whom each favours, where the features come from, and whether a column gives away a sensitive one. It works on any table: use it again for the data of your group project.
donor_records_export.csvFrom: Fundraising & Development, Global Aid Alliance
Purpose of the export: to understand donation patterns, improve fundraising efficiency and increase donor retention.
What the file contains
How the data are collected
Columns
| Column | Meaning |
|---|---|
donation_id | Unique ID of the donation |
donor_id | Unique ID of the donor |
donor_name | Name as given by the donor |
donation_date | Date the gift was received |
donation_amount | Amount of the gift |
currency | Currency of the gift; all gifts are converted to USD |
channel | How the gift was made: Online, Mail or Event |
campaign | The appeal the gift responded to, or General Fund if the donor did not choose one |
region | Region (continent) of the donor's address |
age_range | Age band of the donor |
gender | Gender of the donor: Female, Male, Non-binary, Prefer not to say |
recurring_gift | Yes if the gift is part of a monthly direct debit |
Privacy: donors agree to our privacy notice when they give. Analysis for fundraising purposes is covered by it.
Clustering and classification with scikit-learn: k-means finds voting blocs among US senators, and decision trees and a random forest predict whether a song is danceable. Take the ten questions with you: who made the Senate and Spotify data, what are the label and the features, who decided the categories, and who is in the data?
To submit: run the whole notebook and complete every cell marked #Complete cell. Sections and cells marked optional you can skip.
Run the first code cell to set up the checks. Below an exercise, q1.check() checks your answer, q1.hint()
gives a hint and q1.solution() the solution: try first.
The last cell of the notebook makes an HTML file of your notebook and downloads it. Save the notebook first, run the cell, check the HTML file, and upload it to Canvas.
The code-along for this week's lecture: machine learning.
The ten questions are the core. This is the full Structured Data Audit Checklist from the lecture: use it for the data your group collects, before any analysis or modelling.