Courseiva
MLS-C01Chapter 3 of 15Objective 2.2

Data Preparation and Transformation

Domain 2: Data Preparation and Transformation tackles the dirtiest secret of machine learning: most real-world data is useless in its raw form. For the MLS-C01 exam, you must understand how to turn messy, incomplete, and inconsistent data into a clean dataset a model can actually learn from — because that's what takes up 80% of a data scientist's time, not building models.

12 min read
Intermediate
Updated Jul 23, 2026
Reviewed by Johnson Ajibi· Senior Network & Security Engineer · MSc IT Security

A simple way to picture Data Preparation and Transformation

The Master Chef's Kitchen Analogy

A master chef preparing a complex five-course meal. The chef doesn't just throw ingredients into pots and hope for the best. Instead, she starts by inspecting every single item. She discards bruised apples, cuts off the woody ends of asparagus, and washes grit from the leeks. This is cleaning the data — removing the bad or irrelevant bits.

Next, she transforms the ingredients. She juliennes the carrots into perfect matchsticks, dices the onions uniformly, and zests the lemons into fine curls. This is transforming the data — converting it from its raw state into a consistent format that fits the recipe. A whole carrot is useless for a stir-fry; julienned carrot is perfect. Finally, she engineers the elements. She realises the recipe needs a 'garlic and herb butter'. That's not a single ingredient; it's a feature she creates by combining garlic, butter, parsley, and salt. This is feature engineering — building new, more useful pieces of information from the raw components. A machine learning model, like a chef, cannot work with raw, messy ingredients. It needs clean, transformed, and engineered data to cook up accurate predictions.

How It Actually Works

Data preparation and transformation is the process of taking raw data — the messy, unorganised stuff your sensors, databases, or spreadsheets produce — and converting it into a clean, structured format that a machine learning algorithm can digest. Think of it as the kitchen prep work before a chef starts cooking. Without it, the 'meal' (your model) will taste awful.

The process involves several critical steps. First is data cleaning. This means identifying and fixing errors in your dataset. Common issues include:

Missing values: a cell in your spreadsheet has no data. For example, a customer's age might be blank.

Duplicates: the same customer record appears twice.

Outliers: a value that is wildly different from the rest, like a person's age listed as 999.

Inconsistent formatting: dates written as '01/02/2024' in one place and 'Feb 1, 2024' in another.

To handle missing values, you have options. You can drop the row entirely (remove the customer record), impute the missing value (fill it with the average age of all other customers), or flag the missingness (add a new column that says 'age was missing'). Each approach has trade-offs, and the exam expects you to choose the right one for the scenario.

Next is data transformation. This changes the scale or distribution of your data so that different features (columns) are comparable. For example, if you have 'age' (0-100 years) and 'salary' (£20,000-£200,000), salary will dominate any distance-based algorithm because its numbers are larger. Common transformations include:

Normalisation: scaling values to a range of 0 to 1. Every number gets squeezed into that range.

Standardisation: centering the data around a mean of 0 with a standard deviation of 1. This doesn't force a fixed range but makes the data fit a standard bell curve.

Log transformation: applying a logarithm to compress highly skewed data, like house prices, to make it more normal.

Finally, feature engineering is where you create new columns from existing ones to give the model more signal. For instance, from a 'timestamp' column, you could extract 'day of the week', 'hour of the day', and 'is_weekend'. If you had 'date of birth', you might engineer 'age'. If you have 'address', you might derive 'postal code' or 'city'. The goal is to help the model find patterns it would otherwise miss.

Why does this matter? Machine learning algorithms are purely mathematical. They only understand numbers. They cannot handle text labels ('red', 'green', 'blue') directly. You must encode them. Common encoding methods are:

Label encoding: assigning a number to each category (red=1, green=2, blue=3). This implies an order, which is fine for ordinal data (like 'small', 'medium', 'large') but problematic for nominal data (colours).

One-hot encoding: creating a separate binary column for each category. 'Red' becomes a column with 1 if the colour is red, 0 otherwise. This avoids implying order but expands the dataset's width.

Amazon SageMaker, the AWS service for building ML models, provides built-in tools for all of these tasks. You can use the SageMaker Data Wrangler to visually inspect and clean your data without writing code, or use AWS Glue for serverless ETL (Extract, Transform, Load) jobs that clean and transform data at scale. The key principle is GIGO: Garbage In, Garbage Out. If you feed a model bad data, it will produce bad predictions, no matter how clever the algorithm.

Flowchart showing the sequential stages of data preparation: from raw data through cleaning, transformation, and feature engineering to a clean dataset.

Walk-Through

1

Data Collection and Understanding

Gather raw data from sources like databases, S3 buckets, or CSV files. Understand the structure: number of rows, columns, data types, and what each column represents. This step identifies potential issues early.

2

Data Profiling and Visualisation

Use tools like SageMaker Data Wrangler to generate summary statistics (mean, median, count of missing values) and visualisations (histograms, box plots). This reveals outliers, missing values, and distribution shapes that need correction.

3

Data Cleaning

Fix or remove erroneous data: impute missing values with median or mean, drop duplicate rows, cap or remove outliers, and standardise formatting (e.g., date formats, text case). This ensures data quality.

4

Data Transformation and Scaling

Apply transformations: normalise or standardise numerical features so they are on the same scale. Encode categorical variables using one-hot or label encoding. This prepares data for mathematical algorithms.

5

Feature Engineering

Create new features from existing ones: split timestamps into day/hour, compute ratios of columns, aggregate transaction data per customer. This enriches the dataset with more predictive information.

6

Splitting and Final Validation

Split the cleaned dataset into training, validation, and test sets. Perform any scaling or encoding only on the training set, then apply the same transformations to the validation and test sets to avoid data leakage.

What This Looks Like on the Job

A data scientist at an online clothing retailer is tasked with building a model that predicts which customers will return items. She starts with a raw dataset from the company's database containing customer orders over the last year. The raw data is a mess.

First, she connects to the data stored in Amazon S3 and opens it in SageMaker Data Wrangler. She immediately sees problems. Customer ages are missing in 20% of records. Some postal codes contain non-numeric characters. The column 'date_of_purchase' is a mix of US and UK date formats (MM/DD/YYYY vs DD/MM/YYYY). There are duplicate rows where the same customer made the exact same order twice due to a system glitch.

Her steps are:

Handle missing ages: She chooses to impute the missing ages with the median age of all other customers, because dropping 20% of data would lose too many records.

Fix postal codes: She writes a simple transformation to extract only the numeric characters and drops rows where the code is entirely invalid.

Standardise dates: She converts all dates to a single format (YYYY-MM-DD) using a built-in SageMaker transformation.

Remove duplicates: She deduplicates the dataset by checking for rows where every column is identical, keeping only the first occurrence.

Engineer features: She creates a new column 'days_since_last_purchase' by subtracting the customer's last purchase date from the current date. She also creates 'is_high_value_customer' by flagging customers whose total spend is above £500. She one-hot-encodes the 'product_category' column (e.g., 'Menswear', 'Womenswear', 'Accessories') into separate binary columns.

Once the data is cleaned and transformed, she exports it to a new location in S3, ready for training. The entire process, which would have taken days of manual Excel work, now takes her two hours in SageMaker. The model she trains on this cleaned data achieves 85% accuracy in predicting returns, compared to only 55% when she first tried with the raw data. This concrete improvement in business outcome — reduced return costs, better inventory planning — is why data preparation is the most valuable skill on the job.

How MLS-C01 Actually Tests This

The MLS-C01 exam tests Data Preparation and Transformation heavily, with roughly 20% of questions touching on these topics. The exam loves to present you with a messy, realistic scenario and ask you to choose the correct cleaning or transformation step. They want you to know not just how to do it, but why.

Key topics the exam will hammer you on:

Handling missing values: Know the three main strategies: drop rows, impute (with mean, median, or mode), or flag the missingness. The exam will present scenarios: 'A dataset has 5% missing values in a critical column. What should you do?' The correct answer is usually imputation with the median (especially if outliers are present) or mean (if data is normally distributed). They will trap you by suggesting 'drop all rows with missing values' when the percentage is high.

Encoding categorical variables: You must distinguish between ordinal and nominal data. For nominal data (colours, countries), use one-hot encoding. For ordinal data (t-shirt sizes: S, M, L), use label encoding. A common trap: they will offer one-hot encoding for 'age_group' where the groups are 'child, adult, senior' — this is ordinal, so label encoding is better.

Scaling: Normalisation (min-max scaling) vs Standardisation (z-score). Normalisation is preferred when you know the bounds (e.g., pixel values 0-255). Standardisation is better when you have outliers or unknown bounds. The exam may ask: 'Which scaling method should you use for a feature with extreme outliers?' Answer: Standardisation, because it is less sensitive to outliers than normalisation.

Data leakage: This is a massive exam trap. Data leakage happens when you use information from the future to predict the past. For example, if you normalise your entire dataset (including the test set) before splitting into train and test, you have leaked information. The correct approach is to fit the scaler only on the training data, then transform both train and test sets using that fitted scaler. The exam will deliberately describe a workflow where the candidate normalises the whole dataset first and then splits — this is wrong.

Imbalanced data: Know that you can oversample the minority class, undersample the majority class, or use synthetic data generation (SMOTE). The exam may ask which technique avoids information loss — undersampling loses data, so oversampling or SMOTE is preferred.

AWS services: SageMaker Data Wrangler, AWS Glue DataBrew, and Amazon EMR for large-scale transformations. Know that Data Wrangler is the visual, no-code tool, while Glue is for serverless ETL jobs.

Traps to watch for:

They will offer 'drop duplicates' when the duplicates are actually legitimate repeated measurements (e.g., multiple purchases by the same customer). Understand that duplicate detection is about identical rows, not logically similar rows.

They will suggest 'use the mean to impute missing values' when the dataset has clear outliers that would distort the mean. The median is the safer choice.

They will present a categorical feature with 1000 unique values and suggest one-hot encoding, which would create 1000 new columns — impractical. The correct answer in such cases is to use dimensionality reduction or target encoding.

Memorise these definitions: - Normalisation: scales data to [0, 1]. Formula: (x - min) / (max - min). - Standardisation: centres data to mean 0, std 1. Formula: (x - mean) / std. - One-hot encoding: creates binary columns for each category. - Label encoding: assigns integer labels to categories.

Key Takeaways

Data cleaning removes errors like missing values, duplicates, and outliers; the three main strategies are dropping, imputing, or flagging missing data.

Data transformation changes the scale or distribution of features; normalisation scales to [0,1] while standardisation centres to mean 0.

Feature engineering creates new predictive signals from existing data, such as extracting day-of-week from a timestamp.

One-hot encoding creates binary columns for nominal categories; label encoding assigns integers for ordinal categories — never confuse the two.

Data leakage occurs when you use information from the test set to influence training, e.g., scaling the whole dataset before splitting; always fit scalers only on the training data.

SageMaker Data Wrangler is the visual, no-code tool for data preparation on AWS, while AWS Glue is used for serverless ETL at scale.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Normalisation (Min-Max Scaling)

Scales values to a fixed range, usually 0 to 1.

Sensitive to outliers; a single extreme value can compress the rest.

Formula: (x - min) / (max - min).

Standardisation (Z-Score Scaling)

Centres data to mean 0 with standard deviation 1.

Robust to outliers because it uses mean and std, not min/max.

Formula: (x - mean) / standard deviation.

One-Hot Encoding

Creates a new binary column for each category.

Does not imply any order between categories.

Can greatly increase dataset width if many categories exist.

Label Encoding

Assigns a single integer (1,2,3) to each category.

Implies a natural order, which can mislead the model for nominal data.

Keeps dataset width compact.

Dropping Missing Values

Removes entire rows or columns with missing data.

Simplest to implement but causes data loss.

Only advisable when missingness is random and below 5%.

Imputing Missing Values

Fills missing values with a statistic (mean, median, mode).

Preserves data size and reduces bias.

Requires careful choice of imputation value to avoid distorting distribution.

Watch Out for These

Mistake

Data preparation is a one-time step done at the start of the project and never revisited.

Correct

Data preparation is an iterative process. As you explore the data and build models, you discover new issues and engineer new features, requiring you to go back and clean or transform again.

Beginners think of it as a linear pipeline, but real projects cycle between preparation, modelling, and evaluation multiple times.

Mistake

Dropping all rows with missing values is always the safest approach.

Correct

Dropping rows leads to data loss, which can introduce bias and reduce model performance. It is only acceptable when the missing values are few (e.g., less than 5%) and randomly distributed.

It seems like the simplest solution to avoid 'messing with the data', but in practice it wastes valuable data and can skew results.

Mistake

You should apply scaling to categorical variables after one-hot encoding.

Correct

Applying scaling to binary (0/1) columns from one-hot encoding is unnecessary and can distort the interpretation. Scalers are intended for continuous numerical features, not binary ones.

Beginners think 'all features must be scaled' without understanding that binary features are already on the same scale.

Mistake

Feature engineering means simply renaming columns.

Correct

Feature engineering involves creating new, informative features from existing data (e.g., combining date columns into 'day of week', or calculating ratios). Renaming alone adds no informational value.

The word 'engineering' sounds technical, so beginners assume it means any manipulation, but it specifically means creating new predictive signals.

Mistake

You can train a model on data that still contains text labels if you use a special algorithm.

Correct

No algorithm can process raw text labels directly. All categorical data must be numerically encoded (e.g., one-hot or label encoding) before any ML algorithm can use it.

Some beginners think algorithms are 'smart enough' to understand words, but they are purely mathematical and only operate on numbers.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

Should I normalise or standardise my data?

Use normalisation (min-max scaling) when you know the bounds of your data, like pixel values 0-255. Use standardisation (z-score) when you have outliers or unknown bounds, as it is more robust to extreme values.

What is data leakage and why does it matter for the exam?

Data leakage is when information from outside the training set influences the model, making it perform artificially well. A classic example is scaling the entire dataset before splitting into train and test, which leaks test data statistics into training.

Can I use the same imputation value for both training and testing?

Yes. You must calculate the mean (or median) using only the training data, then use that same value to impute missing values in both the training and test sets. Never recalculate the mean on the test set.

What is the difference between one-hot encoding and label encoding?

One-hot encoding creates a separate binary column for each category, avoiding implied order. Label encoding assigns integers (1,2,3) to categories, which implies an order. Use one-hot for nominal data (colours) and label encoding for ordinal data (sizes).

When should I drop missing values instead of imputing them?

Drop missing values only when they are few (under 5% of rows) and randomly missing. If the missingness is patterned or represents a large portion, imputation or flagging is preferred to avoid bias and data loss.

What is SMOTE and when would I use it?

SMOTE (Synthetic Minority Over-sampling Technique) creates synthetic examples of the minority class in an imbalanced dataset. Use it when you have very few examples of a rare class (like fraud detection) to help the model learn better.

Terms Worth Knowing

Keep going

You've finished Data Preparation and Transformation. Continue through the MLS-C01 study guide to build a complete picture of the exam.

Done with this chapter?