Key takeaway
- Data preparation turns raw data into model-ready inputs. Learn the steps for missing values, scaling, encoding and class balance, and where agents fit.
Data preparation is the work of turning raw, inconsistent data into clean, complete and well-formed inputs that a machine learning model can learn from. It covers profiling the data, fixing quality problems, transforming features and checking that the result is fair to the people and cases the model will serve.
This roadmap is for data scientists, ML engineers and analytics leads who want a repeatable order of work before modelling. It covers the steps, the choices inside each step, a comparison of common techniques, how AI agents change the work, and what to do first.
Why does data preparation matter for AI?
A model predicts from the historical data it is given, so gaps, duplicates and skew in that data become gaps, duplicates and skew in its output. Most business data is not ready for modelling: it is spread across systems, mixes text and numbers, and carries human errors. Preparation is where these problems are found and decided on in the open, with a record of each decision, rather than discovered after a model misbehaves.

What are the steps in a data preparation roadmap?
- Profile the data with exploratory data analysis: row and column counts, types, missing values, ranges, relationships between features and the target.
- Clean it: handle missing values, outliers and duplicate rows.
- Transform it: scale numeric features and encode categorical ones.
- Engineer features: select, construct or aggregate features that carry signal.
- Balance and split: deal with class imbalance and hold out data for testing.
- Document each step so the same pipeline can be rerun and audited.
How do you handle missing values, outliers and duplicates?
The scikit-learn imputation guide notes that many real world datasets contain missing values, often encoded as blanks, NaNs or other marker values, and that most estimators assume every value is numerical. Its basic option is to discard rows or columns with missing values, which comes at the price of losing data that may be valuable. A better strategy, it says, is to impute: infer missing values from the known part of the data, for example with a constant or the mean, median or most frequent value of each column. It also points out that keeping a record of which values were missing can be informative, which is what its MissingIndicator does.
Outliers need a decision rather than a reflex. Some are errors and should be corrected or removed, and some are real events the model must see. Duplicate rows can overweight some cases and make a model look more accurate than it is, so remove exact duplicates and investigate near duplicates. Features that hardly vary add little, and the same is true of a feature that repeats another almost exactly, so review both before training.
How do you scale and encode features?
The scikit-learn preprocessing guide says standardisation of datasets is a common requirement for many estimators, which may behave badly if features do not look roughly like standard normally distributed data. Its scalers compute their statistics on the training set so that the same transformation can be applied to the test set later, and that order matters: fit on training data only, to avoid leaking information from the test data. The guide also says that if data contains many outliers, scaling with the mean and variance is likely not to work well, and a robust scaler can be used instead.
Categorical features must be converted to numbers. The guide describes ordinal encoding, which turns categories into integer codes, and warns that many estimators would read those codes as ordered, which is often not wanted. One-hot encoding creates one binary feature per category and avoids that problem.
| Task | Common options | Watch out for |
|---|---|---|
| Missing values | Drop rows or columns, impute with a constant or a column statistic, add a missing indicator | Dropping can discard useful data |
| Scaling | Standardisation, min-max scaling, robust scaling | Fit on training data only |
| Categorical encoding | Ordinal codes, one-hot encoding, target encoding for many categories | Integer codes imply an order |
| Class imbalance | Random over-sampling, SMOTE, under-sampling, class weights | Resample training data only |
| Too many features | Feature selection, PCA, aggregation | Keep features that can be explained |
How do you engineer features and balance classes?
Feature selection removes columns that add load without helping the output. Feature construction builds new columns from existing ones, and principal component analysis combines original features linearly into fewer new ones when the data is very wide. Feature aggregation summarises detail, for example daily store sales into monthly totals, which reduces the number of records and the processing time. The scikit-learn guide adds that centring and scaling do not remove linear correlation between features, and that PCA with whitening can be used for that.
When one class is much rarer than another, a classifier can score well by ignoring it. The imbalanced-learn documentation describes random over-sampling as sampling with replacement from the available minority samples, and SMOTE as interpolating between existing samples instead of copying them. Apply resampling to training data only, and keep a test set that reflects real class frequencies.
How do you make data preparation explainable and fair?
Fairness is easier to protect when each choice is recorded. Keep a short log of what was dropped, imputed, scaled or encoded, and why. Compare feature distributions before and after cleaning, check that groups affected by the model are not removed by missing value rules, and watch for drift between training data and new data. Feature importance helps reviewers see which inputs drive predictions. Related reading: roadmap for algorithm and model explanation and edge analytics applications.
How do AI agents change data preparation?
Agents can now profile new datasets, propose cleaning steps, write pipeline code and run it. That speeds the work but raises the stakes on context: an agent that cleans data without knowing what a column means, who owns it or which policy governs it can quietly remove the very records a model needs. Data preparation done by agents therefore needs the same record of decisions as human work, with approvals for changes that affect a model in production. For governed data and context, see ElixirData, XenonStack's Context OS.
What should you do first?
- Choose one model or report and list the data it depends on.
- Profile that data and write down the quality problems found.
- Fix missing values, duplicates and outliers with a stated rule for each.
- Build scaling and encoding into a pipeline fitted on training data only.
- Log every step so the preparation can be rerun and reviewed.
To map one decision your agents make, and the data and policy it depends on, book a Context Workshop. See what happens in the workshop.
Frequently asked questions
What is data preparation in machine learning?
It is the process of cleaning, transforming and organising raw data so that a model can learn from it. It includes profiling, handling missing values and outliers, scaling, encoding and feature engineering.
Should you drop rows with missing values or impute them?
Dropping rows is the basic option but loses data that may be valuable. The scikit-learn guide describes imputing, which infers missing values from the known part of the data, as a better strategy, and suggests keeping track of which values were missing.
Why fit scalers on training data only?
Fitting on training data and then applying the same transformation to test data keeps information about the test set out of training, so the test result is an honest estimate.
How do you handle imbalanced classes?
Common approaches are random over-sampling, SMOTE-style interpolation, under-sampling or class weights, applied to training data only and judged on a test set that keeps real class frequencies.
Where do AI agents fit in data preparation?
Agents can profile data, propose fixes and run pipelines, but they need the meaning, ownership and policy context of each dataset, and every change should be recorded and approved where it affects production models.
Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.
Ready to put AI agents to work? Explore ElixirClaw, the agentic OS platform to build, orchestrate and govern AI agents.
Explore the XenonStack platform family: ElixirData · ElixirClaw · ElixirHub · NexaStack · MetaSecure · Neural AI · AgentGRC · AgentSRE · AgentAnalyst · AgentInstruct · AgentRAI · AgentScrum · AgentSearch · AgentForce · AI Aviator · SAIF Aviator · CohortIQ · XenonStack AI · XenonStack UAE