In data and analytics: what may be done with what can be done, and how to protect the people in the rows.
Knowledge Discovery in Data · University of the Philippines Cebu
Real harms, known failures, consent, and the applicable Philippine law.
Identifiers, k-anonymity and generalization: auditing and reducing re-identification risk.
Bias, transparency, and the tests professionals apply to their own work.
Week 4 previewed scraping etiquette and deferred the full treatment to this week. With the whole KDD pipeline now covered, the question of whether an analysis should be done receives its own week.
Every row describes a person who is not present, and should be handled as if that person were watching.
Any data that identifies a person, on its own or when combined with other data.
e.g. a name, a student number, or age + barangay + course together
Personal information the law protects more strictly: health, education, government IDs, religion…
e.g. a student's GPA is education data, so it is sensitive
"Personally identifiable information": the common industry name for roughly the same idea as personal information.
e.g. email address, phone number, home address
The person the data is about. The law gives them rights over it.
e.g. the student in row 3 of a class list
A person's clear, informed "yes" to their data being used for a stated purpose.
e.g. ticking "use my answers to evaluate this course"
Anything done with personal data: collecting, storing, analysing, sharing, deleting.
e.g. running a groupby on a class survey is processing
Data collected for one purpose is used for that purpose only.
e.g. enrolment phone numbers are not a marketing list
Collect and keep only the columns the purpose really needs.
e.g. birth year instead of full birth date
A column that names one person by itself.
e.g. student_id, full name, email
A column that is harmless alone but can point to one person when combined with others.
e.g. age, barangay, birth date, sex
Matching an "anonymous" record back to a real, named person.
e.g. joining a health table to a voter list on ZIP + birth date + sex
Every combination of quasi-identifiers is shared by at least k records. k = 1 means someone stands alone.
e.g. k = 3: every record shares its combination with at least two others
Making a column less precise so more records look alike.
e.g. age 19 → "18–20"; exact budget → ₱50M band
Withholding any number or row that describes too few people.
e.g. no average published for a group of fewer than 5
Changing data so that nobody in it can be identified, by anyone, any more. Hard to achieve.
e.g. only group totals released, every group large
Replacing names with a code. Rows still link together, so it is not anonymous.
e.g. 2024-001 → 3e0f221a8d0c
A systematic tilt in data or analysis, so results lean one way for some group.
e.g. an online survey that misses people without internet
Whether an analysis or decision treats different groups of people equally well.
e.g. the same error rate for rich and poor barangays
Cynthia Dwork, Frank McSherry, Kobbi Nissim and Adam Smith formalise how much noise to add.
RAPPOR collects browser statistics without exposing any one user.
iOS 10 uses it to learn from phones without reading individual data.
The 2006 paper receives a top prize in theoretical computer science.
It makes the coin-flip survey from Part B exact: every answer carries enough noise that no single person can be identified.
The guarantee is about each person: a published result looks almost the same whether or not any one person’s record is in the data.
The Census Bureau added noise to its 2020 results using differential privacy.
Apple (since 2016) and Google (since 2014) collect usage statistics this way.
Microsoft uses it for Windows telemetry (2017); LinkedIn for advertiser statistics (2020).
A national census adopting it marks the shift from hiding names to limiting what any table can reveal.
SourceUS Census Bureau: Differential privacy; Wikipedia: Differential privacy
As in earlier weeks, a block with a ▶ Run / Edit button runs in the browser. This week’s small examples use the lab’s four students, so every re-identification can be checked by eye; the flood audits run in the companion notebook.
Blocks that hold a checklist, a consent statement or a framing to adapt have no Run button and are not part of the notebook.
pd.__version__the installed pandas: 3.0.5 on the laptop, 2.2.0 in the browsert.dtypeseach column’s type: str on the laptop, object in the browserData about people carries risk for them and for the analyst.
Weeks 3–10 covered collecting, cleaning, exploring and presenting data. This part addresses a prior question: what the people in the rows are owed.
In a notebook, a row is four values. For the person described, it may be a location an abuser should not learn, a diagnosis an employer should not see, or a grade that invites family shame.
Stalking, discrimination in hiring or insurance, public humiliation and identity theft are all documented consequences of leaked datasets.
Publication happens once; the person bears the effects permanently. Released data cannot be fully withdrawn.
The burden of care rests on the analyst, the one person who sees the whole table.
"Anonymized" queries for 650k users. Reporters identified user 4417749 from her own searches within days, since searches reveal personal details.
Movie ratings, no names. Researchers matched rating patterns to public IMDb reviews and re-identified users, because rating patterns are distinctive.
Aggregated jogging routes revealed the layouts of military bases. Even aggregates leak when the group is small and distinct.
In each case the publishers believed the data was safe to release, and each failure began with removing the names. Anonymised means nobody in the data can be identified any more; each release was only called that, and each was re-identified: records matched back to named people. An aggregate is a summary over a group, such as a total or an average.
Replacing "the names were removed" with an audit that runs in pandas.
| Case | What was released | How it was re-identified |
|---|---|---|
| Sweeney, 1997 | State employee health records with names removed | ZIP + birthdate + sex uniquely identified most people; matched against a public voter roll |
| AOL, 2006 | 20 million search queries, user IDs replaced with numbers | The searches themselves were identifying; journalists traced user 4417749 to a named individual |
| Netflix Prize, 2006 | 100 million movie ratings, subscriber IDs removed | Matched against public IMDb reviews; a handful of dated ratings identified subscribers |
The pattern is the same in each case: the identifier was removed and the data was still identifying, because it could be joined against something public. (A ZIP code is a US postcode; a voter roll is the public list of registered voters, with names and birth dates.) Sweeney’s work led to k-anonymity, which Part B computes on the course dataset. The Netflix data came out in 2006; the re-identification paper followed in 2008.
Each release was safe against the data available that day. None survived a join with something that appeared later. (A quasi-identifier, in the code comment, is a column that is harmless alone but identifying in combination; Part B makes it precise.)
Data minimisation means collecting only what the purpose needs. A column that was never collected cannot be joined against anything. An "anonymised" column can be, by data that does not yet exist.
Consent is a person's clear, informed "yes" to a stated use of their data. People provide data for a purpose: enrollment, delivery, a health consultation. Reusing it for another purpose is a new decision that requires its own justification.
Lending a car "to go to the market" does not cover a road trip to Manila, however carefully the borrower drives.
Collected for X, used for X. The enrollment form's phone numbers are not a marketing list.
Only the minimum that serves the purpose is collected. Every extra column is additional risk held by choice.
An extension of week 4: a reachable post is not permission to compile a profile. Aggregating public traces creates something new and more dangerous.
Philippine law, enforced by the National Privacy Commission. If the rows describe people, this act sets the analyst's obligations.
| Concept | Meaning |
|---|---|
| Personal information | Data that identifies a person, alone or combined |
| Sensitive personal info | Health, education, government IDs, and more; stricter rules |
| Data subject rights | To be informed, to access, to correct, to object |
| Accountability | Whoever processes the data answers for its protection |
Education records, such as GPAs, are sensitive personal information under the act. This week's lab dataset is a small example of regulated data.
The Philippine Data Privacy Act of 2012 is not a general principle; it imposes specific, checkable duties on anyone processing personal data.
Scope is about processing personal information, not about being a company. A class survey with names in it is covered.
Personal data is like cash given for one errand, to be used only for that errand, in the amount needed, kept safe, and returned or destroyed afterwards. (This is a summary for analysts, not legal advice.)
Consent given for one stated purpose does not extend to later ideas. Re-using data for a new purpose needs a new basis.
Whether the person would have agreed to this use at the moment of consent. If this is uncertain, consent must be sought again.
For a study, a researcher scrapes thousands of public social-media posts with usernames and publishes the dataset, arguing that "it was all public." Does that argument hold?
C: compilation creates something the separate posts were not.
A thousand scattered posts and one searchable dataset of named people are different objects with different risks. Politeness (B) answers the server-load question, not the persons-in-the-data question. At minimum, the data should be de-identified and aggregated, with a known legal basis.
Week 4 asked whether data may be taken. This week asks what is created when it is combined.
The compiled dataset requires justification, not only the requests that gathered it.
Next: privacy as a testable engineering problem.
Auditing and reducing risk in pandas.
Weeks 6–7 covered grouping and counting rows (groupby). This part uses the same operation to measure how exposed each record is, and then to reduce that exposure.
The risk lies not only in the obvious column but also in the combination of apparently harmless columns around it.
studentsthe lab’s four students (the lab calls this table df; here df is the flood data)student_ida direct identifier: names one person on its ownage, barangayquasi-identifiers: harmless alone, identifying togetherstudent_id: direct identifier, names a person. age, barangay: quasi-identifiers, harmless alone, identifying together. gpa: sensitive, the value to be protected.
"Latanya Sweeney showed that 87% of Americans are uniquely identified by ZIP code, birth date and sex alone, and re-identified the governor of Massachusetts in an 'anonymized' medical dataset using those columns."Quasi-identifiers + one outside dataset = a name
The method is always the same: the "anonymous" table is joined to a public one (voter rolls, social media, a class list) on the quasi-identifiers, and the names are recovered. It is week 6's merge (joining two tables on shared columns), used to re-identify.
"A 21-year-old from Apas in this class" is not a name, but in a small class it identifies exactly one person, as a name would.
The same skills make the analyst the appropriate person to run the audit first.
The rows are grouped by the quasi-identifiers and the group sizes checked. A group of 1 is a person who can be singled out. k-anonymity: a table is "k-anonymous" when every combination appears at least k times.
df.groupby(["age", "barangay"])put rows with the same age and barangay in one group.size()count the rows in each group19 Lahug 3three students share "19, Lahug": each hides among three21 Apas 1a group of one: that student is exposed, so k = 1["barangay"] only. Is anyone still alone?Result on the lecture laptop (select to reveal)
(19, Lahug) holds 3 students and (21, Apas) holds 1: k = 1, so student 2024-003 is exposed. By barangay alone, Lahug has 3 and Apas still 1: the barangay by itself identifies her.
The 21-year-old from Apas is unique, so anyone who knows those two facts learns that student's GPA. The smallest group is 1, so this table is not 2-anonymous.
The audit is the groupby from weeks 6 and 7, applied to the quasi-identifiers. k is the size of the smallest group: here 1, so the table is not even 2-anonymous.
Any statistic over a group of one, such as its mean gpa, publishes that student’s own value. Suppression, later in Part B, withholds such cells.
The effect of one additional column.
The same group-size audit, on the 34,079 flood projects: how many projects are alone in their combination of region, province, year and budget?
The browser cannot download the data, so the flood blocks have no Run button; the companion notebook runs them.
requests.get(url)download the whole table in one request(34079, 15)34,079 projects, 15 columnsGrouped by region, the smallest group has 180 records. No single project can be picked out; every row has at least 179 others that look identical. (These rows are projects, not people; the audit works the same way on either.)
The smallest group size is the k. Higher is safer, and 180 is well above common thresholds.
len(g)how many groups: 18 regionsg.min()the smallest group's size, which is the k(g == 1).sum()g == 1 gives True/False per group; .sum() counts the Trues (True counts as 1)| Quasi-identifiers | Groups | Records alone (k=1) | % unique |
|---|---|---|---|
| region | 18 | 0 | 0.0% |
| region + year | 180 | 1 | 0.0% |
| region + province + year | 1,944 | 96 | 0.3% |
| + budget rounded to ₱1M | 16,646 | 10,534 | 30.9% |
A rounded budget figure does not appear identifying. Adding it takes the dataset from nothing unique to nearly a third of records unique. This is the risk of quasi-identifiers: each is innocuous, but the combination is not.
The same audit runs for every column list, so it is wrapped in a function (week 2: a named, reusable piece of work). Each experiment is then one line.
def audit(cols):define a function called audit that takes a list of column namesalone = (g == 1).sum()how many groups hold exactly one recordprint(f"{len(g):,} ...")an f-string: :, adds thousands commas, :.1% shows a share as a percentage(df.budget/1e6).round()budget in millions of pesos, rounded: ₱12,345,678 → 12.030.9%almost a third of all projects are alone in their groupGeneralisation means making a column less precise so more records look alike. With the budget column kept in ₱50M bands instead of exact millions, uniqueness falls from 30.9% to 2.7%. With place also generalised (province up to region), it falls to 0.4%.
The exact cost and province of a project are no longer available. Its band and region still are, which is enough for most questions.
In a photo taken from further away, faces blur into a crowd, but the crowd can still be counted and located.
Every generalisation that protects someone also removes something a legitimate analysis could have used. Ignoring this trade-off leads to poor results on both.
For an analysis of regional totals, ₱50M bands cost nothing. For a study of cost variation within a province, they remove the needed detail, so a different protection is required, not a different rounding.
student_id is removed outright. The quasi-identifiers are then made less precise (exact age becomes an age band), so the groups grow.
drop(columns=["student_id"])remove the direct identifierpd.cut(safe["age"], bins=[17, 20, 25], …)replace exact age with a band: 18–20 or 21–25drop(columns=["age"])and drop the exact age itself"19, Lahug" and "20, Lahug" merge into "18–20, Lahug": one larger group instead of two small ones. Larger k, lower risk, same broad analytical shape.
Bands lose detail: a study of "GPA by exact age" is impossible when age becomes two bins. That loss is the cost of protection, and someone must decide how much is acceptable.
Risk remains; the k=1 cells persist under new labels.
The dataset becomes safe but analytically useless.
Not the analyst alone. Purpose, audience and the data subjects' interests all matter, which is why review processes exist.
A raw table would not be published, but a summary table appears safe. The counts show that the "average GPA in Apas" is one specific student's GPA.
df.groupby("barangay")["gpa"]group the students by barangay and look at the gpa column.agg(["mean", "count"])two summaries per group: the average and how many students\ at the end of a line"this line continues on the next one"1.25, 1an average over one student: it is that student's GPA.query("count >= 2") to the end. What is published now?Result on the lecture laptop (select to reveal)
Apas: mean 1.25 over 1 student, which is that student’s exact GPA. With the threshold only Lahug remains (mean 1.75, 3 students): the cell of one is suppressed, as statistical agencies do.
Suppression means withholding any number that describes too few people. Statistical agencies suppress any cell below a minimum count (often 3–10) for exactly this reason. The rule: no statistic for a group smaller than the threshold.
Cordillera Administrative Region, 2026: one project. Publishing "the average project in CAR in 2026 cost X" publishes that single contract’s exact value.
c.nsmallest(3)the three smallest counts; a blank region means “same as the row above”safe = c[c >= 5]keep only cells with 5 or more records: suppression(180, 179)180 cells before, 179 after: one cell was withheldA statistic over a group of one is the individual. Over a group of two, either party can subtract its own value and recover the other.
Any group below a threshold, commonly 5 or 10, is suppressed. The count of suppressed cells is published so the table is honest.
If the total and all groups but one are published, the missing one follows by arithmetic. A second cell is suppressed to protect the first.
Two overlapping aggregations can be differenced to recover an individual. This is what differential privacy formalises.
The second rule is frequently overlooked: suppressing exactly one cell while publishing the total reveals the suppressed value.
Suppression stops one bad query. It does not prevent two overlapping queries being subtracted. Differential privacy addresses this directly: it adds a little random noise to every answer.
In a survey where each person privately flips a coin before answering, no single answer is reliable, so no one is exposed, yet the overall percentage remains close.
Each answer is almost exactly as likely whether or not any single record is in the dataset. So the answer cannot reveal that record.
size=3 to size=1000 and print noisy.mean().round(1). What happens to the noise?Result on the lecture laptop (select to reveal)
eps = 0.1: answers spread from about 1238 to 1266; at eps = 10 they stay within 0.1 of 1263. Averaged over 1,000 answers the noise cancels (1263.5, 1262.9, 1263.0): repeated queries leak the truth, which is why the budget must be spent, not reset.
laplace_noise(scale=1/eps)a stand-in name, not a real pandas function: "a random number, usually small, positive or negative"epsepsilon, the privacy budget: how much each answer may revealnoisythe published number, e.g. 1,261 or 1,265 instead of exactly 1,263Small cells in a published table. Simple, and the reader can see what was withheld.
Releasing a dataset others will analyse. Wide bands, k above the threshold, as with the budget column.
A query service answering many questions over time. The only one that survives repeated, overlapping queries.
They are not competing techniques; they answer different threats. The choice depends on how the data will be accessed, not on which sounds most rigorous.
Hashing turns any text into a fixed-length scramble of
characters (a digest); SHA-256 is one standard recipe. Replacing student_id
with its digest keeps rows linkable across files without showing the id. This is useful, but it is pseudonymisation (a code instead of a name), not anonymisation.
The b before the quotes turns the text into bytes, which hashing needs; [:12] keeps the first 12 of 64 characters.
A pseudonym is a nickname that hides the name, but activity under the nickname still links together, and anyone with the list of nicknames can reverse it.
The same input always gives the same hash, so anyone who can guess the id space (for example, a four-digit year plus three digits) can hash every candidate and match.
A stable pseudonym exists so that rows still connect, and that connection is what re-identification attacks exploit.
Pseudonymized data is still personal data under privacy law, and the obligations remain.
student_id was removed before the class dataset was published. A classmate says it is now anonymous. Is it?
B: the audit comes before the claim.
"We removed the names" is where AOL and Netflix started, too. The quasi-identifiers are grouped, the k=1 cells found, and values generalized until the groups are large enough; only then can anonymity be claimed, with care. (D is not an argument.)
Anonymity is a property to be verified, not a label to be declared.
The k-anonymity audit is three lines of pandas and should be run on any shared dataset.
Bias, transparency, and self-applied tests.
Part B covered measuring and reducing the risk to the people in a table. This part addresses wider questions: who the data leaves out, and whether the analysis is fair to them.
Week 5's "meaningful gaps" at population scale: surveys miss the unconnected, complaint data misses those who have stopped complaining.
Records of past decisions encode past discrimination. Naive analysis converts past bias into an apparently "objective finding."
When the sensitive column is dropped, its correlates remain: barangay can proxy for income, school for class. These are the correlations from week 8.
Bias is a systematic tilt, so results lean one way for some group; fairness asks whether an analysis treats different groups equally well. A proxy is a column that stands in for another (barangay for income). This is not an argument against analysis. It requires knowing whom the data represents and omits, and stating this in the findings.
The week-9 caveats: "this data covers X, not everyone" is also a caveat.
"The data is biased" is not a finding. How the bias entered determines whether and how it can be corrected.
They need different fixes: reweighting (counting under-represented rows more heavily), better collection, or abandoning the question. Conflating them produces confident, wrong corrections.
Weighing only the people who came to the gym is selection bias. A bathroom scale that always reads 2 kg light is measurement bias. Both give a wrong average, for different reasons.
| Question | Response to an unfavourable answer |
|---|---|
| Should this exist? What is the purpose, and does this dataset serve it? | The data is not collected. Minimisation is the only protection that cannot fail. |
| Who is exposed? k computed on the quasi-identifiers. | Generalisation until k clears the threshold, with the cost recorded. |
| Who bears the risk? Is it the same people who get the benefit? | If the subjects carry the risk and others take the benefit, that asymmetry needs explicit justification. |
| What if the claim is wrong? Who is harmed by a false claim here? | A correspondingly higher evidence threshold. Named parties need more than aggregates do. |
None of these is answered by a library. They are judgements, and the professional obligation is to make them explicitly and in writing — so that others can disagree before publication rather than after.
They are quick to apply and identify most problems early.
Whether the methods, described accurately on a front page, could be defended rather than explained away.
Whether the analyst could describe directly to the person in row 3 what was done with their data.
A need to construct a justification is itself the answer. A supervisor, an ethics board or the NPC's guidance should be consulted before, not after.
There is no personal privacy question here: the data concerns public money and corporate entities. That does not make publication risk-free.
A false claim about a named firm is defamation (a false public statement that harms a reputation) rather than a privacy breach, but the obligation to get it right is identical.
Every field kept can leak, be subpoenaed (ordered handed over by a court), or be re-identified later by data that does not exist yet. A retention period is how long data is kept before deletion.
Which analysis needs this column. If none does, it is not collected. Retro-fitting privacy is far harder than not collecting.
| Location | Why it survives a delete | Response |
|---|---|---|
| Backups | Restore points predate the deletion — by design | Retention window known; deletions timed against it |
| Derived tables | Aggregates and exports built before the delete | Lineage tracked: the outputs that used this input |
| Version control | A committed file lives in history forever | Data never committed, since a later delete does not remove it |
| Other people’s copies | Anything shared or downloaded | A log of who received what, and when |
Version control (e.g. git) keeps every saved version of a set of files; one saved version is a commit. Lineage is the record of which outputs were built from which inputs. "We deleted it" is usually "we deleted one copy". Before deletion is promised, the copies must be enumerated. The backups that protect against data loss are also the reason deletion takes time.
Compute group sizes for region; then region+year; then +province; then +budget rounded to the million. Count k=1 groups at each step.
Identify the single extra column that raises uniqueness most, and explain why.
Widen the band until fewer than 1% of records are unique. State the resolution lost.
Two sentences: what was generalised, and which analyses remain valid on the released version.
Step 4 is what a data steward produces. The protection is useful only if the next analyst knows how it affects their questions.
Grouping by region gives a minimum group size of 180. Province, year, and budget rounded to the nearest million are added. What happens?
Mean project cost is published per region-year. One cell (Cordillera, 2026) contains a single project. What has been published?
Four students, one sensitive column. The lab classifies the identifiers, finds the k=1 group, fixes it by dropping and banding, and identifies a leaking aggregate. ~45 minutes.
Identifier triage, groupby().size() as a k-anonymity audit,
pd.cut age bands, and count-based suppression.
Hash an id with hashlib.sha256 and argue pseudonymous-vs-anonymous; find the riskiest quasi-identifier combination.
Purpose-bound consent and minimal collection, required by law under RA 10173.
Quasi-identifiers are audited with a groupby; k=1 means a person is exposed.
Remove direct ids, band the quasi columns, never publish a group of one; hashing gives only a pseudonym.
Every report states whom the data covers and whom it omits.
In one sentence: the people in the rows deserve the same care as the findings about them.
A synthesis of the whole course, followed by the final presentations.
The National Privacy Commission's plain-language primer on RA 10173, covering obligations and rights. privacy.gov.ph
An account of Latanya Sweeney re-identifying Governor Weld's medical record, the work that led to k-anonymity.
Both are linked on the course page beside this deck and the lab.
After finding a k=1 group in the lab, Sweeney's method is easier to follow.
The whole KDD process in one view, followed by the final presentations.
DS 227 · Knowledge Discovery in Data