Data Preparation for Machine Learning: A Complete Checklist
Data preparation for machine learning means profiling the data, cleaning it, removing leakage, splitting it correctly, then encoding categories and scaling numbers so a model can learn from it. TensorTurn automates the analysis half in your browser (profiling, alerts, leakage flags, target analysis) and produces a preprocessing playbook for your chosen target that you can export as Python code, with an AI data editor for the cleaning steps in between.
What data preparation covers
A model can only be as good as the table it learns from. Data preparation is everything between the raw export and the first training run: understanding what each column contains, fixing errors, deciding what the model is allowed to see, and converting values into the numeric form algorithms need. It is also where most silent failures start. A model trained on leaky or badly split data will report excellent metrics and then fail in production, and nothing in the training log will warn you.
The end-to-end checklist
- 1. Define the target and the prediction moment: what you predict, and what information exists at the time of prediction.
- 2. Profile every column: type, missing %, unique count, distribution, skewness, top categories.
- 3. Check associations between columns and with the target to spot redundancy and leakage.
- 4. Clean: fix types, whitespace, case, placeholders, duplicates and impossible values.
- 5. Review outliers and decide which are errors and which are rare but real.
- 6. Remove leakage: post-outcome columns, IDs that encode the label, rows shared across splits.
- 7. Split into train, validation and test using a scheme that matches how the model will be used.
- 8. Impute, encode and scale, fitting every transformation on the training split only.
- 9. Check class balance and decide on weighting or resampling.
- 10. Re-profile and document every step so the pipeline can be repeated on new data.
Profiling and target analysis
Profiling tells you what you actually have. TensorTurn computes, on upload, the inferred type, missing %, unique count, min and max, skewness, kurtosis and histograms for each column, plus a mixed-type association matrix over every column pair: Pearson correlation for numeric pairs, bias-corrected Cramér's V for categorical pairs and the correlation ratio for categorical-numeric pairs. Once you choose a target, target analysis reports class balance, the predictive signal of each feature, leakage flags for features that are suspiciously predictive, and whether missingness in a feature depends on the target.
Cleaning and outliers
Cleaning for machine learning is the same work as cleaning for analysis, with one extra question for every change: would this information be available when the model makes a real prediction? Use TensorTurn's AI data editor to trim, normalise, cast, map values, fill or drop missing values and drop duplicates with reviewable steps. For outliers, TensorTurn shows per-column IQR fences (1.5x for mild, 3x for extreme) and ranks the most anomalous rows by modified z-score, so you can inspect specific rows before removing any.
Leakage: the most expensive mistake
Leakage is any route by which information about the answer reaches the model during training but will not be there at prediction time. Classic examples are a "cancellation_reason" column in a churn dataset, a "discharge_date" in a readmission dataset, and the same customer appearing in both train and test. TensorTurn flags features that are suspiciously predictive of the target and detects train/test leakage and duplicate rows. A suspiciously perfect validation score is a reason to investigate, not to celebrate.
Choosing a split
| Split strategy | Use when | Avoid when |
|---|---|---|
| Random split | Rows are independent and identically distributed | Data has time order or repeated entities |
| Stratified split | Classification with imbalanced classes | Regression targets (use binned stratification instead if needed) |
| Time-based split | Forecasting, or any model that predicts the future from the past | Data has no meaningful time order |
| Group split | Several rows per customer, patient or device | Each row is a separate entity |
| Cross-validation | Small datasets where one split is too noisy | Time series without a forward-chaining variant |
For time-ordered data, also check drift. TensorTurn's datetime analysis measures PSI between the first and second chronological half of the data (under 0.1 stable, 0.1 to 0.25 moderate, above 0.25 major), which warns you when the past may not represent the future.
Encoding and scaling
| Technique | What it does | Good for |
|---|---|---|
| One-hot encoding | One binary column per category | Low-cardinality categoricals, linear models and neural networks |
| Ordinal encoding | Maps categories to integers | Ordered categories, and tree models generally |
| Target encoding | Replaces a category with a smoothed target statistic | High-cardinality categoricals; must be fitted inside cross-validation to avoid leakage |
| Standard scaling | Zero mean, unit variance | Linear models, SVMs, neural networks, k-means, KNN |
| Min-max scaling | Rescales to a fixed range | Neural networks and bounded inputs |
| Robust scaling | Centres on the median and scales by IQR | Skewed data with outliers |
| Log transform | Compresses long right tails | Highly skewed positive values like income or counts |
Tree-based models such as random forests, XGBoost and LightGBM do not need scaling, which is one reason gradient boosting is a strong default for tabular data. Distance-based and gradient-trained models do.
The preprocessing playbook, exportable as Python
For a chosen target, TensorTurn builds a preprocessing playbook: a feature plan that says, column by column, what to drop, how to impute, how to encode and what to scale, informed by the profile and target analysis. You can export it as Python code to use in your own pipeline, or describe the model in chat and TensorTurn generates and runs the whole training notebook with scikit-learn, XGBoost, LightGBM, PyTorch or Keras on cloud GPUs or your own connected machine.
Frequently asked questions
What are the steps of data preparation for machine learning?
Define the target, profile the data, clean it, review outliers, remove leakage, split into train and test, then impute, encode and scale using statistics from the training split only. Finish by checking class balance and documenting the pipeline so it can be repeated.
Should I clean data before or after the train/test split?
Row-level fixes that do not learn from the data, such as trimming whitespace, fixing types and removing duplicates, can happen before the split. Anything that computes a statistic, such as mean imputation, scaling or target encoding, should be fitted on the training split only.
Do I need to scale features for XGBoost or random forests?
No. Tree-based models split on thresholds and are unaffected by feature scale. Scaling matters for linear models, SVMs, neural networks and distance-based methods such as KNN and k-means.
How do I know if my dataset has leakage?
Warning signs are features that predict the target almost perfectly, columns created after the outcome, and duplicate rows across train and test. TensorTurn flags suspiciously predictive features and detects train/test leakage automatically.
Can TensorTurn export the preprocessing as code?
Yes. The preprocessing playbook for a chosen target can be exported as Python code, so you can reuse the feature plan in your own pipeline.