Unsupervised learning
Units, Features, and Preprocessing for Unsupervised Data
Build an analysis-ready feature space by controlling units, time, duplicates, missingness, and preprocessing boundaries.
By the end you can
- Define the unit of analysis and observation time for an unsupervised dataset
- Identify duplicate evidence, leakage, and aggregation choices that distort structure
- Distinguish missingness from a genuine zero or absent event
- Construct a preprocessing pipeline that can be applied consistently to new data
Example
Preprocessing decisions that manufacture clusters
Each example below produces structure. The structure may be technically real and analytically misleading. The fourth one is not a hypothetical. It has a report, a date and a wreck.
The Mars Climate Orbiter launched on 11 December 1998 and was lost on 23 September 1999. NASA's mishap investigation board reported on 10 November 1999. The executive summary of its Phase I Report gives the root cause: “The MCO MIB has determined that the root cause for the loss of the MCO spacecraft was the failure to use metric units in the coding of a ground software file, “Small Forces,” used in trajectory models.”
Thruster impulse data were passed in pound-force seconds where newton-seconds were expected. That understates the trajectory effect by exactly the 4.45 conversion factor. The estimated first periapsis came out at 57 km against a planned 226 km. Two years later, in 2002, the U.S. General Accounting Office described the same finding from the outside: “A NASA mishap investigation team determined that the loss was due to the mistaken use of English rather than metric units in the navigation software.”
No column was empty. No value was malformed. Nothing in the numbers themselves showed that the two sides meant different things by them. That is exactly the failure a distance function cannot see either.
- Duplicate customers: A household with four linked accounts appears four times and pulls a centroid toward its behavior.
- Unequal observation windows: Long-tenure users accumulate more events and separate from newcomers mainly because they had more time.
- Post-event features: Repair cost recorded after a failure makes operating regimes look unusually easy to distinguish.
- Unit mismatch: The Mars Climate Orbiter's ground software passed thruster impulse in pound-force seconds instead of newton-seconds, a factor of 4.45, and the estimated first periapsis came out at 57 km instead of the planned 226 km.
- Silent imputation: Replacing all missing sensor values with zero creates a distinct “outage cluster” that analysts misname as a machine state.
A fleet dataset with three incompatible meanings of “vehicle”
An operations team clusters a table. Some rows represent vehicles, others represent daily summaries, several represent repair visits. The algorithm returns crisp groups. The groups mainly separate row types.
Unsupervised methods are especially vulnerable to this mistake, because no target exposes the mismatch. Before distance has meaning, every observation must answer the same analytical question.
A coherent feature space begins with a coherent unit.
Analogy
Comparing athletes after changing the rules of each event
In one competition table, one row records a runner’s best race, another records an entire season, and a third records a medical visit. Ranking those rows by similarity would mostly reveal how the records were constructed.
Real datasets are subtler than the competition, because construction choices can hide inside identical-looking rows. Columns that line up perfectly can still be measuring different events.
Google Flu Trends is the documented version of that sentence. The model was fitted by matching 50 million search terms against 1,152 data points. Lazer and colleagues, in Science in 2014, gave the result its epitaph: “In short, the initial version of GFT was part flu detector, part winter detector.” The columns looked like a measurement of influenza. In part they were a measurement of the calendar. The system “has missed high for 100 out of 108 weeks starting with August 2011”, running to September 2013, and the authors named the underlying trap “big data hubris”.
An independent group had reached the same verdict from its own analysis a few months earlier, in PLOS Computational Biology in 2013: “We identified substantial flaws in the original and updated GFT models at all three geographic scales, including completely missing the first wave of the 2009 influenza A/H1N1 pandemic, and greatly overestimating the intensity of the A/H3N2 epidemic during the 2012/2013 season.” A column named for a disease that misses the pandemic and hits every winter was never the column its name claimed.
Uniform columns do not guarantee uniform semantics.
Visual
The dataset contract for structure discovery
Five choices determine whether rows are comparable before any algorithm runs.
1. Entity
Choose the person, device, account, document, region, or event represented by a row.
2. Time reference
Fix the window, cutoff, or episode used to construct every feature.
3. Evidence policy
Decide how repeated events, duplicates, and linked records contribute to one observation.
4. Missingness meaning
Separate not measured, not applicable, unavailable, censored, and genuine zero.
5. Transform boundary
Fit imputers, scalers, encoders, and reducers on the intended reference data only.
Comparable rows require a shared entity, time frame, and evidence policy.
Comparison
Four values that often become the same number by accident
A stored zero can hide several operationally different states, and the difference between them carries measurable information.
Every patient treated at two Boston hospitals over one year, 2005–2006 — 669,452 people — across 272 laboratory test types. Agniel, Kohane and Weber published what that material showed in the BMJ in 2018, and their abstract states the finding: “The presence of a laboratory test order, regardless of any other information about the test result, has a significant association (P<0.001) with the odds of survival in 233 of 272 (86%) tests.” The timing of when a test was ordered beat the result of the test itself as a predictor of three-year survival in 118 of 174 tests, 68% of them.
An independent group at a different institution, writing in the American Journal of Epidemiology, named the same mechanism informed presence bias. Appearing in the record is itself informative about the subject's state, rather than a neutral fact.
So a cell that says nothing was measured is not a cell that says zero. In 86% of these tests it was carrying prognostic signal of its own. Imputing it away deletes that signal and invents a measurement that never happened.
Observed zero
The quantity was measured and its value was zero.
- Carries direct measurement evidence
- May be meaningful for distance
- Should remain distinguishable from absence
- Can still contain sensor error
Missing measurement
The system expected a value but did not obtain one.
- May reflect outage or workflow failure
- Can correlate with entity type
- Requires an explicit handling rule
- Often deserves a missingness indicator
Not applicable
The feature has no valid meaning for this observation.
- Should not be interpreted as low magnitude
- May require separate modeling
- Can expose mixed populations
- Needs documentation in the data contract
No recorded event
Nothing appears in the event log during the window.
- Could mean inactivity or missing logging
- Depends on instrumentation coverage
- May require exposure normalization
- Should be checked against source completeness
Steps
Create an analysis-ready table with a traceable contract
The pipeline should make every feature reproducible. It should make every missing value interpretable. Step 2 is the one that gets waved through.
The rate at which one entity becomes several unlinked rows has been measured on real record systems. The Patient Identification and Matching Final Report of 2014, prepared for the Office of the National Coordinator for Health Information Technology, gives one organisation's numbers: “For example, Kaiser Permanente (which has 17 instances of Epic across its regions) reported a match rate of greater than 90 percent within each instance; that rate fell to around 50 percent to 60 percent when sharing between regions using a separate instance of Epic or with outside Epic partners.” Same organisation, same software vendor, seventeen installations. Roughly half the cross-region records failed to find their twin.
Five years later the U.S. Government Accountability Office reported the same order of magnitude: “A 2014 study found that as few as 50 percent of records are accurately matched when organizations exchange information.”
Auditing cardinality before aggregation therefore means assuming, until you have counted, that a large share of the rows describing one entity across sources are not linked to each other. The centroid you compute is weighted by that failure.
1. Write the row definition
State the entity, timestamp, observation window, and inclusion rules in one sentence.
2. Audit cardinality
Check duplicates, linked entities, repeated episodes, and group dependence before aggregation.
3. Build feature lineage
Record source fields, transformations, units, and availability time for each column.
4. Encode missingness deliberately
Choose imputation, indicators, exclusion, or separate treatment based on operational meaning.
5. Freeze the transformer
Version the fitted preprocessing object together with the clustering or reduction model.
Key idea
Preprocessing can leak future or global information
Fitting a scaler on every month may seem harmless, because clustering has no label. But a production system using future distribution statistics has seen information unavailable at assignment time. The same issue affects imputation, vocabulary building, feature selection, and PCA. Fit transformations on the declared reference period. Then apply them to later or held-out observations.
The size of that effect is not a matter of taste. Rosenblatt and colleagues ran four datasets, three phenotypes and over 400 pipelines, and reported in Nature Communications in 2024: “Leakage via feature selection and repeated subjects drastically inflates prediction performance, whereas other forms of leakage have minor effects.” Selecting features on the combined training and test data moved one prediction from chance level, r = 0.01, to r = 0.48. The inflation was Δr = 0.03 for age, 0.17 for matrix reasoning and 0.47 for attention problems. Repeating 20% of subjects across the split added Δr = 0.28 on its own — the duplicate-entity problem of step 2, priced.
Nor is this a niche failure. Kapoor and Narayanan surveyed the published literature in 2023: “we find 17 fields where leakage has been found, collectively affecting 294 papers and, in some cases, leading to wildly overoptimistic conclusions.”
Unsupervised does not mean exempt from temporal leakage.
Case
The patient ID band that was 36% malignant
A column can carry information nobody intended. The KDD Cup 2008 data is the cleanest demonstration of it.
The organizers supplied 1,712 training patients, 118 of them with cancer, described by 117 features and 102,294 candidates that were never explained to entrants. The winning team found its signal in the patient identifier instead. Section 2 of their winner's report is titled “Leakage in Patient ID”, and it splits the identifier range into three bands: “between 0 and 20,000 (254 patients; 36% malignant); between 100,000 and 500,000 (414 patients; 1% malignant); and above 4,000,000 (1044 patients, of them 1.7% malignant)”.
The three bands add to exactly 1,712, every training patient. Against a cohort rate of 6.9%, the first band is 5.2 times the cohort rate and 36 times the malignant share of the second. The split generalized to the test set. A model reading the identifier scored well without reading the images.
Figure
The feature matrix is already a model of the world
Rows and columns do not arrive neutral. Aggregation chooses which events matter, missing-value rules define equivalence, and transformations decide which differences survive. Kaufman and colleagues call leakage “one of the top ten data mining mistakes”. Their definition is “the introduction of information about the data mining target” that should not have been available. Nothing in it depends on having labels. A scaler fitted on the whole timeline meets the same description.
The reason to version the contract alongside the algorithm is that defensible choices, made by competent people on one fixed dataset, do not converge. Twenty-nine teams — 61 analysts in all — were given the same football dataset. Their “estimated effect sizes ranged from 0.89 to 2.93 in odds ratio units, with a median of 1.31”. On identical data, “Twenty teams (69%) found a statistically significant positive effect and nine teams (31%) observed a nonsignificant relationship”. Overall the 29 analyses used 21 unique combinations of covariates.
A different consortium in a different field reproduced the phenomenon. Seventy independent teams were given one fMRI dataset and nine pre-specified hypotheses, and they produced 70 different workflows. The report in Nature says it plainly: “The flexibility of analytical approaches is exemplified by the fact that no two teams chose identical workflows to analyse the data.”
A trustworthy unsupervised pipeline therefore versions the dataset contract alongside the algorithm. When structure changes, analysts can investigate the data definition before blaming the model. On this evidence the data definition, not the model, is where the spread lives.
Most clustering failures begin before the clustering algorithm.
Key takeaways
- Every row must represent the same analytical unit and comparable observation window; the Mars Climate Orbiter shows that a unit disagreement is invisible inside well-formed numbers.
- Duplicates and linked entities are measured, not hypothetical: greater than 90 percent match within one Epic instance, around 50 percent to 60 percent across instances at Kaiser Permanente.
- Missing, zero, not applicable, and no recorded event are different states — the presence of a test order alone predicted survival in 233 of 272 (86%) tests.
- Preprocessing can leak future information even without supervised labels: feature selection on combined training and test data moved one prediction from r = 0.01 to r = 0.48.
- Feature lineage should include source, unit, transformation, and availability time, because a KDD Cup patient identifier band ran 36% malignant against a 6.9% cohort rate.
- The fitted preprocessing pipeline belongs to the deployed unsupervised system; unversioned analytic choice spread 29 teams from 0.89 to 2.93 in odds ratio units on identical data.