IMEN891K / IDSC501 / AXGS-501 · Data Engineering · Fall 2026

5. Pre-processing II: Transformation & Reduction

Sangwoo Mo · POSTECH
Industrial & Management Engineering

Where We Are

PART I · Collection and Preparation PART II PART III Collect Lec 2 Explore Lec 3 Preprocess Lec 4-5 Storage Lec 6-13 Monitoring and Updates Lec 14-17 preprocessing changes the representation; some choices also remove information

Recap: Four Stages of Preprocessing

01 Cleaning Wrong values in one table 02 Integration one view Tables that disagree 03 Transformation 12.4 0.42 0.03 0.00 870 1.00 Values a model can read 04 Reduction Less data, same signal

Transformation

01 Cleaning Wrong values in one table 02 Integration one view Tables that disagree 03 Transformation 12.4 0.42 0.03 0.00 870 1.00 Values a model can read 04 Reduction Less data, same signal

Recap: Data TypesNumbers get rescaled; discretization turns numbers into categories

Data splits into numerical (continuous, discrete) and categorical (nominal, ordinal); normalization acts on numerical data and discretization turns numbers into categories
The type of a column decides the tool

Three Branches of Transformation

Transformation Scaling Numbers continuous → continuous Linear Scalers Non-Linear Transforms Direction and Unit Norm Encoding and Binning categorical ↔ numeric One Column per Category Embeddings Cuts and Information Loss Making Features nothing → a new column Written by a Person Learned by the Model Borrowed, Already Trained

Scaling Numbers

Transformation Scaling Numbers continuous → continuous Linear Scalers Non-Linear Transforms Direction and Unit Norm Encoding and Binning categorical ↔ numeric One Column per Category Embeddings Cuts and Information Loss Making Features nothing → a new column Written by a Person Learned by the Model Borrowed, Already Trained

Why Scale at AllDistance-based models add up raw units, so the widest column decides

two columns from one machine, on one raw axis 0 500 1,000 1,500 2,000 2,500 3,000 3,500 spindle speed (rpm, revolutions per minute): 1,679 to 3,009 cycle time: 28 to 36 s, three pixels wide how far apart two rows can be, column by column Δcycle time = 8 Δrpm = 1,330
In raw Euclidean distance, the rpm difference dominates the cycle-time difference

The Evaluation Must Match DeploymentDefine what will be new at prediction time before splitting the records

Deployment questionUseful splitWhat a random row split can hide
Predict future eventsEarlier train; later testFuture information reaches training
Predict new machinesHold out whole machinesSame-machine patterns occur on both sides
Predict new customersHold out whole customersRepeated identity makes the test easier
A held-out row can still share an entity or future information with training

Caveat: One Machine on Both Sides

Random rows

MachineTrainTest
M180 sampled cycles20 held-out cycles
M280 sampled cycles20 held-out cycles

New-machine evaluation

MachineRole
M1Train
M2Test
Testing new machines requires machines that training has never seen

Fitted Transformation StateFit learns parameters; transform reuses the saved parameters

StepFit on trainTransform new rows
Scalingmin, max or mean, SDreuse the same numbers
Encodingcategory vocabularyreuse the same columns
PCAcenter and axesproject onto the same axes
Fit once on training rows, then apply the saved state

Linear ScalersThree scalers, one shape: subtract a center, divide by a spread

SCALER THE SAME FORMULA, TWO ESTIMATORS BREAKDOWN POINT Min-max ( x − min ) / max − min 0% Standardization ( x − mean ) / standard deviation 0% Robust ( x − median ) / interquartile range 25%
Picking a scaler is picking how many bad rows it takes to move the answer

Min-Max Scalingx′ = (x − min) / (max − min) maps the training range onto [0, 1]

Min-max scaling formula mapping x to the zero-one interval
The minimum maps to 0, the maximum to 1. Fit both on train only

Demo: Fit on Train, Apply to TestTrain cycle times stay at 28, 32 and 36 seconds

1. Can a transformed test value exceed 1?   2. Does refitting change the training rows?
40 s

Answer: Reusing a ScalerAt test = 40, the saved training range produces 1.5

Fitting rowsmin / maxtrain 36 →test 40 →
Train only28 / 361.0001.500
Train + test28 / 400.6671.000
New observations can lie outside the fitted training range

Caveat: Min-Max and OutliersOne outlier is enough to squash every other value

20 cycle times 0 1 the same 20, plus one glitch at 950 s 0 1 all 20 rows inside the first 2%
The maximum defines the range, so the maximum defines everything

Z-Score StandardizationEach training column gets mean 0 and standard deviation 1

as recorded: cycle time (s) 40 60 80 100 120 standardized: mean 0, standard deviation 1 −2 −1 0 1 2 the bars are identical; only the numbers under them changed
z = (x − μ) / σthe shape is untouched; only the axis is relabeled
A right tail stays a right tail. Standardizing does not make a column normal

Robust ScalingThe median and the IQR barely move when one row goes wrong

Original scatter and the same data centered on its median
x′ = (x − median) / IQRIQR = interquartile range
The median moves to zero and the outliers stay far out. That is intended

Demo: Feature Scalers300 cycles from one computer numerical control (CNC) machine, both columns on one axis

1. Compare scalers with a mistyped rpm.   2. Did scaling repair the error or change the reference statistics?

Answer: Scaling and OutliersScaling changes the reference statistics, not the recorded event

ScalerReference statisticsEffect of an extreme value
MinMaxmin and maxclean values compress into a narrow range
Standardmean and SDcenter and spread can move
Robustmedian and IQRresists some extremes; keeps the outlier
Scaling changes representation; it does not validate or remove a value

Log TransformLog turns ratios into equal steps

Raw value13264128log2(value)01234567
log2(2x) − log2(x) = 1x > 0
Each doubling becomes the same gap. Normality is not guaranteed

Unit Vector NormalizationScale each row, not each column, to length 1

Normalizing a vector to unit length and unit vectors on the circle
x′ = x / ‖x‖2then x′Ty′ is exactly the cosine similarity
Every row lands on the unit circle; the dot product is now cosine similarity

Encoding and Binning

Transformation Scaling Numbers continuous → continuous Linear Scalers Non-Linear Transforms Direction and Unit Norm Encoding and Binning categorical ↔ numeric One Column per Category Embeddings Cuts and Information Loss Making Features nothing → a new column Written by a Person Learned by the Model Borrowed, Already Trained

Encoding vs BinningOne turns categories into numbers, the other turns numbers into categories

ENCODING a model cannot multiply a name Seoul 1 0 0 one-hot · label · count · binary · embedding BINNING a continuous column rarely repeats a value 28.4 s B2 equal width · equal frequency · clustering
What the model can use decides which way you cross

Nominal and Ordinal CategoriesA numeric code can introduce order and spacing into the model

Nominal: no known order

ColorArbitrary code
red1
green2
blue3

Ordinal: a known order

SizeOrdered code
small1
medium2
large3
Color codes invent an order; size codes express an existing order

One-Hot EncodingOne indicator column per category, so no order is invented

Color column with Green, Red, Black, Orange mapped to four indicator columns
x → ( 𝕀[x = c1], …, 𝕀[x = ck] )k categories become k columns whose sum is always 1
With an intercept, k one-hot columns are linearly dependent. Dropping one removes this dependency

Choosing an EncodingOrder, the number of categories and the model decide the encoding

Data meaningStarting choiceCheck
Unordered categoriesOne-hotWidth and unknown values
Known ordered levelsOrdinal codesThe supplied order matches the meaning
Text or many related categoriesLearned embeddingVocabulary, model version and validation
Start with the category meaning, then check width and held-out behavior

Demo: Categorical EncodersSix training rows; reuse their category vocabulary for test

1. Compare one-hot with integer codes.   2. Apply the fitted vocabulary to an unseen test color.
BEFORE
AFTER ·

Answer: An Unseen CategoryA fitted encoder needs an explicit policy for a new value

Encoder policyBlue at test timeConsequence
One-hot, ignore unknown[0, 0, 0, 0]keeps four fitted columns
Integer codes, unknown = -1-1unknown remains distinct
Add a test-only Blue columnfive columnschanges the fitted representation
Keep the fitted vocabulary; define how unknown values are represented

Vector EmbeddingA learned model maps each category to a short real vector

Seoul 0.6 0.3 0.1 Busan 0.8 0.5 0.3 Tokyo 0.4 0.2 0.9 embedding model learned, not written by hand d(Seoul, Busan) = 0.35  ·  d(Seoul, Tokyo) = 0.83
Distances now differ between pairs. In one-hot, every pair of categories is equally far apart

An Encoding Cannot Restore a Binned ValueBinning loses within-bin differences; encoding represents the resulting category

Measured number

cycle time = 28.4 s

Bin category

B2: [25 s, 30 s)

One-hot representation

B1 B2 B3
 0  1  0
A numeric output does not imply that the original measurement was preserved

Why DiscretizeContinuous values give almost every row its own case

one column: 36 rows, 29 different values 303336 the same column: four cases B16 rowsB212 rowsB316 rowsB42 rows
Four bins replace 29 values. Where the cuts go is the whole question

Binning by HistogramEqual width keeps the scale, equal frequency keeps the counts

EQUAL WIDTH 26 8 1 2 3 EQUAL FREQUENCY 8 8 8 8 8 40 cycle times, five bins either way
width = (max − min) / kvscount = n / kthe same k, two different things held constant
Equal width: 26, 8, 1, 2, 3 rows. Equal frequency: 8 in every bin

Making Features

Transformation Scaling Numbers continuous → continuous Linear Scalers Non-Linear Transforms Direction and Unit Norm Encoding and Binning categorical ↔ numeric One Column per Category Embeddings Cuts and Information Loss Making Features nothing → a new column Written by a Person Learned by the Model Borrowed, Already Trained

Hand-Crafted FeaturesNo column holds it, so you compute one: TF-IDF (term frequency × inverse document frequency)

Term in one maintenance logtfdf of 1,000 logslog(N/df)Weight
the121,0000.000.0
pump43001.204.8
cavitation2124.428.8
w = tf · log(N / df)N = 1,000 logs  ·  df = how many of them contain the term
The most frequent word scores zero. A person decided that is the right behavior

Learned FeaturesThe network learns the features and the classifier together

CLASSIC MACHINE LEARNING Raw signal Feature extractiona person writes the formula Classifiertrained on those features Prediction tuned by hand learned DEEP LEARNING Raw signal Feature extraction and classifier one network, one loss, learned together Prediction
Fit your own encoder or reuse a versioned pretrained encoder

Case study: YouTube-8MThe dataset ships features, not videos

YouTube-8M category thumbnails
Feature extraction is also compression, and it is irreversible

Reduction

01 Cleaning Wrong values in one table 02 Integration one view Tables that disagree 03 Transformation 12.4 0.42 0.03 0.00 870 1.00 Values a model can read 04 Reduction Less data, same signal

Three Branches of Reduction

Reduction Fewer Columns columns out, rows kept Principal Components Extraction vs Selection Feature Selection Fewer Rows rows out, columns kept Sampling Design Survivorship Quality-Based Curation Fewer Bytes nothing out, fewer bits Lossless Lossy

Why Reduce at AllColumns, rows and bytes each cost something different

Fewer columns Distances stop separating and the model fits noise Fewer rows You pay to store, move and label every one of them Fewer bytes Storage and transfer are a bill that arrives every month
Removing rows or columns changes learning; lossless compression preserves the data

Fewer Columns

Reduction Fewer Columns columns out, rows kept Principal Components Extraction vs Selection Feature Selection Fewer Rows rows out, columns kept Sampling Design Survivorship Quality-Based Curation Fewer Bytes nothing out, fewer bits Lossless Lossy

Extraction or SelectionKeep some original columns, or mix all of them into new ones

SELECTION keep some of the original columns 5 columns in, 3 of the same columns out filter · wrapper · embedded EXTRACTION make new columns from all of them 5 columns in, 3 new columns out principal components (PCA) · random projection
Selection keeps names you can read. Extraction keeps information you cannot name

Recap: PCA as a Fitted TransformReuse the training center and axes when new observations arrive

Principal axes over a point cloud
znew = (xnew − μtrain) Vtrain,k
Projection keeps selected directions and discards the rest

Demo: PCA Projection AngleTurn the axis and watch how much of the variation survives

1. Find a direction that keeps more variance.   2. Is retained variance enough to choose model features?

Answer: What PCA KeepsLarge retained variance does not guarantee useful predictive features

QuestionCheck
What survives?Variation along the chosen training axes
What disappears?Variation in discarded directions
Does the model still work?Evaluate with held-out observations
Validate the retained representation, not only its variance

Three Families of Feature SelectionCompare model use and relative fitting cost within one selection procedure

FamilyWhat it looks atModel fitsBlind spot
Filterthe columns alone, no modelnonea pair that only works together
Wrapperthe model’s score on a subsetmanythe search itself overfits
Embeddedthe model’s own coefficientsonethe answer is tied to that model
Compare cost, interactions and held-out performance before choosing a selection method

Wrapper Feature SelectionA wrapper compares feature subsets through repeated model fits

Candidate feature subset

temperature + vibration

Fit and validate

Train on training folds
Score on validation folds

Compare another subset

temperature + current

Repeat within the same protocol
Repeated subset search can overfit the validation evidence

Caveat: Features That Work Only TogetherA univariate score can miss a predictive feature interaction

Four synthetic observations

valve Avalve Bdefect
000
011
101
110

One column alone

A = 0: one pass, one defect
A = 1: one pass, one defect

A alone cannot separate them

The pair together

A ≠ B → defect

A = B → pass

Useful combinations can look uninformative when each column is scored alone

Embedded MethodsSome models select features during fitting; the result depends on the model and training data

FeatureIllustrative fitted coefficientInterpretation
Vibration0.8Used by this fitted model
Temperature0.3Used by this fitted model
Humidity0.0Removed by this fitted model
A zero coefficient describes one fitted model, not the absence of a real relationship

Fewer Rows

Reduction Fewer Columns columns out, rows kept Principal Components Extraction vs Selection Feature Selection Fewer Rows rows out, columns kept Sampling Design Survivorship Quality-Based Curation Fewer Bytes nothing out, fewer bits Lossless Lossy

Sampling vs CurationBoth drop rows: sampling follows a design, curation follows quality

SamplingCuration
GoalA smaller set with known proportionsA better set: quality, consistency, coverage
TechniquesRandom, systematic, stratified, clusterFiltering for quality and coverage
Used forLess computation, class imbalanceTraining sets for large models, labeling budgets
ProportionsKept, or changed on purpose (imbalance)Changed by what the filters remove
Sampling decides which rows to keep; curation decides how good they must be

Sampling DesignThe selection rule determines which parts of the population survive

MethodHow rows are chosenFailure to check
Simple randomDraw rows at randomSmall groups may be missed
SystematicEvery kth recordA periodic list can align with k
StratifiedSample within each groupKeep the intended group proportions
ClusterSelect whole groupsOne factory may not represent the rest
Check the population structure before choosing the sampling rule

Sampling to Fix ImbalanceDropping majority rows raises the minority share from 17% to 44%

BEFORE majority 40 · minority 8 · minority share 17% majority class minority class drop 30 majority rows AFTER majority 10 · minority 8 · minority share 44% majority class minority class
Resampling changes class prevalence. Evaluate and calibrate on the deployment distribution

Caveat: Survivorship BiasThe rows you kept are not the rows you lost

Bomber diagram with hit locations concentrated on the wings and fuselage
This shows the bombers that came back. Reinforce where there are no dots

Data CurationCuration filters for quality instead of sampling at random

Sankey diagram of a crawl reduced by language, heuristic, deduplication and model-based filters
This pipeline keeps 1.4% of the crawl as the training set

Fewer Bytes

Reduction Fewer Columns columns out, rows kept Principal Components Extraction vs Selection Feature Selection Fewer Rows rows out, columns kept Sampling Design Survivorship Quality-Based Curation Fewer Bytes nothing out, fewer bits Lossless Lossy

Lossless or LossyCompression restores the original bit for bit, or only an approximation

Lossless compression restores the original; lossy compression uses a smaller compressed box and restores an approximation
The lossy box is smaller, and its changes stay

Lossless Master CopyKeep one lossless copy, because a lossy decision cannot be revisited

LosslessLossy
RestoresThe original, bit for bitAn approximation
Typical dataText, code, logs, tabularImages, audio, video
FormatsZIP, PNG, GZIP, Parquet with Snappy or ZstdJPEG, MP3; lossy H.264 / WebP
RatioLimited by entropyOften much higher, tunable
The catchSometimes not small enoughThe decision cannot be revisited
Text and logs stay lossless; media is where lossy pays

Fitting Preprocessing StepsFit on train, apply to test: every fitted step remembers something from the rows it saw

StepWhat it remembersWhat leaks if you fit on everything
Imputationthe column mediantest rows move the median
Scalingmean and standard deviationthe test spread enters every train row
Encodingthe list of categoriesa category that exists only in test
Binningthe bin edgesedges drawn around test values
Feature selectionthe columns keptcolumns kept because they help on test
PCAthe componentsaxes rotated to fit test variance
z = (x − μtrain) / σtrainthe same two numbers go to test and to every future row
Refit inside every fold; ship the final fit to testing and serving

Takeaway: Every transform and reduction is a decision

A scaler or an encoding decides what the model may compare The center, the spread and any order you invent all end up inside the model Know which reductions you can undo Lossless compression restores; dropped rows and quantized values do not Every fitted step carries state Split for deployment, fit on train, and reuse the saved state
← → / Space · S notes · O overview · F fullscreen · number + Enter
Speaker notes