UNSW Sydney · FACULTY OF COMPUTER SCIENCE

INFS3822 Chap.5 Data Preparation and Feature Engineering

- one subject, every graph, every model, every mark
7 Chapters4-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 5 of 10 · INFS3822

Data Preparation and Feature Engineering

Data preparation controls what a model is able to learn. This chapter distinguishes cleaning from deleting difficult cases, explains one-hot and ordinal encoding, scaling and transformation, and separates feature creation, selection and dimensionality reduction. It applies the central anti-leakage rule: split first, learn transformations on training evidence, and apply them unchanged to testing and future observations.

In this chapter

What this chapter covers

  • 01

    Missing values and valid outliers

  • 02

    One-hot and ordinal encoding

  • 03

    Min-max and standard scaling

  • 04

    Log transformation

  • 05

    Feature creation and selection

  • 06

    Principal component analysis

  • 07

    Training-only transformations

Worked example · free

Prepare a mixed customer table

Q [4 marks]. A table has channel, ordered tier, purchase dates, skewed spend and a response label. State a preparation plan. (4 AskSia practice marks) These marks are for rehearsal and are not an official university marking scheme.
The funnel narrows raw observations into modelling evidence through cleaning, transformation and feature work.The funnel narrows raw observations into modelling evidence through cleaning, transformation and feature work. The side notes show two controls: preserve legitimate difficult cases and exclude information unavailable at decision time. Raw rows: scope, types, missingnessClean + encode + scaleCreate + select featuresTrain / test evidenceremove errors, not inconvenient casespreserve decision-time availability
The funnel narrows raw observations into modelling evidence through cleaning, transformation and feature work. The side notes show two controls: preserve legitimate difficult cases and exclude information unavailable at decision time.
  • +1One-hot encode nominal channel and justify ordinal encoding or indicators for tier.
  • +1Create recency from dates using only information available at the decision time.
  • +1Inspect spend and consider a log transform or robust scaling for the skewed distribution.
  • +1Split before fitting imputers, scalers, feature selectors or dimensionality reduction.
Encode by variable meaning, derive time-safe recency, transform skew only with a reason, and learn every preparation step from training evidence alone.
Sia tip — Ask whether a feature exists at inference before asking how predictive it is.
Glossary

Key terms

One-hot encoding
Representing nominal categories with separate binary indicator columns.
Ordinal encoding
Mapping categories to ordered numeric levels when a genuine order exists.
Feature selection
Choosing a subset of relevant inputs through filter, wrapper or embedded methods.
Dimensionality reduction
Creating a lower-dimensional representation that retains useful variation or structure.
FAQ

Data Preparation and Feature Engineering FAQ

Why must preparation be fitted on training data?

Imputation values, scaling parameters, selected features and components are learned from data. Letting the test set influence them leaks information from supposedly unseen evidence and produces an optimistic evaluation. Fit on training rows, freeze the transformation and apply it unchanged to testing rows.

When should I use one-hot encoding?

Use it for nominal categories that have no meaningful order, such as channel or colour. Assigning integers would imply greater-than relationships that do not exist. For truly ordered categories, ordinal encoding may be justified, although indicators remain useful when spacing between levels is not meaningful.

Are all outliers errors?

No. Some are recording mistakes; others are rare but valid observations that may matter most to the decision. Investigate origin and context before removing them. Report the rule, compare sensitivity and avoid improving model scores by deleting legitimate difficult cases.

What belongs in a feature contract?

Record source fields, types, units, allowed categories, missing-value meaning, time cut-off, transformation formula and output order. Save fitted encoders, imputers and scalers with the estimator. Test ordinary, missing, boundary, rare and unseen-category rows through training and deployment implementations so a schema or ordering difference is found before it corrupts live predictions.

Study strategy

Assessment move

Create a preparation ledger with variable type, missingness, decision-time availability, transformation and reason. Draw the train/test boundary before any learned step. For every engineered feature, explain what source fields it uses and whether those fields existed at prediction time. Rehearse one leakage diagnosis in each practice session.

Work through a mixed table by classifying each operation as a fixed rule or a learned transformation. Parsing a documented date format can be fixed; estimating an imputation value, scaling range, selected feature set or principal component learns from data and must be fitted inside the training boundary. For nominal categories, explain why indicator columns avoid invented order.

For ordinal categories, state the order and question whether numeric spacing is meaningful. For skewed numeric data, inspect the distribution before proposing a log or robust transformation and keep the target units visible when interpreting results. Build a timestamp audit beside the variable ledger. Record when each field is created, when the prediction is required and whether the field would be available for a new case.

Derive one feature manually from source fields, then reproduce it through the pipeline. Include missing values, a rare valid category, an unseen category and a boundary value in a small reference set. This catches differences in mapping, feature order and time handling that aggregate accuracy may conceal.

Practise split order with a written sequence: reserve final evidence, fit preparation on training rows, apply the fitted objects unchanged, compare candidates through validation, lock the completed procedure, then open the final set once. When using cross-validation, remember that every learned preparation step belongs inside each training fold.

Challenge common instructions such as remove outliers, fill missing data and reduce dimensions by asking what evidence justifies them and what information may be lost. A rare case may be precisely the event the model must handle. End each revision session by diagnosing one suspicious result: implausibly high performance, a category failure after release, or a test distribution that looks identical to training.

Trace it through target leakage, split contamination, schema mismatch and transformation drift before changing the estimator.

Working through Data Preparation and Feature Engineering in INFS3822? Sia is AskSia’s AI Computer Science tutor — ask any INFS3822 Data Preparation and Feature Engineering question and get a clear, step-by-step explanation grounded in how INFS3822 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 103 of your UNSW Sydney subjects - and 1,000+ Bibles across every Australian university.
Sia - your INFS3822 tutor, unlimited, worked the way the exam marks it
The full 4-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works
INFS3822 · Artificial Intelligence for Business Analytics - independent study guide on the AskSia Library. More UNSW Sydney subjects · Microeconomics across all universities