Skip to content
GenAI Learn/Data, Training & the ML Pipeline
Browsing as a guest. Sign in to save your progress and earn XP as you complete chapters.

Cleaning, Labeling & Preparing Data

4 min read

You'll learn to

  • -Name the common cleaning steps: missing values, duplicates, inconsistent formats and junk
  • -Run a cleaning pass on a small messy table, and add a simple engineered feature
  • -Explain why data quality sets the ceiling for a model

Raw data is almost never ready to train on directly. It is a familiar claim that data scientists and ML engineers spend most of their time cleaning and preparing data, not modeling, and the reputation is well earned.

An Analogy: Preparing Ingredients

A chef spends much of the day washing, peeling, trimming and measuring before any cooking happens. A great recipe cannot rescue muddy vegetables. Training data is the ingredients, and cleaning is the preparation.

What "Cleaning" Actually Involves

  • -Handling missing values means deciding whether to fill them with a reasonable estimate, drop the incomplete example, or leave a gap the model can learn to handle.
  • -Removing duplicates and near-duplicates matters because repeated examples can quietly bias a model toward whatever is over-represented.
  • -Fixing inconsistent formats is needed because the same value written several ways, such as dates, units or capitalization, must be standardized before it can be compared.
  • -Filtering out low-quality or irrelevant examples matters too. Not every collected example is useful, and junk can hurt more than it helps.

The demo does all four on six messy rows. Look for the row that was dropped as unrepairable, the duplicate that disappeared, the missing age that was filled, and the two new columns made from the signup date.

Press Run: six messy rows become four clean ones, with two features added

Labeling: Turning Raw Data Into Supervised Examples

For supervised learning, someone or something has to attach the correct label to each example. That can mean human annotators reviewing examples one by one, using labels a product already produces (a purchase is itself evidence that a recommendation worked), or the self-supervised trick covered earlier of generating labels automatically from the data's own structure.

A useful rule of thumb: the quality ceiling of a model is set by the quality of its data, not by the sophistication of the algorithm. A powerful algorithm trained on messy, mislabeled data will reliably lose to a simple algorithm trained on clean, well-labeled data.

Feature Engineering

A feature is one input measurement the model sees. Especially for classical ML, and less so for deep learning, which often learns useful representations directly from raw data, practitioners transform raw data into more useful features before training. The demo turned a raw signup date into "weekday" and "month", which are often more directly predictive than the raw timestamp.

In practice, this whole chapter is what the pandas library exists for. Reading messy CSVs or database exports into a DataFrame, then using methods like .dropna(), .fillna(), .drop_duplicates() and .apply(), does exactly the cleaning and feature engineering described here, instead of hand-written loops over raw Python lists.

Interview Signal is part of Pro

See a real weak answer next to a real strong one for this exact topic.

Quiz is part of Pro

Test what you just read with a short quiz, and bank the XP.

Discussion0

Join the Discussion

Sign in to leave comments, reply to others, or like insights.

Sign In to ScaleDojo

No comments yet. Be the first to start the thread!