tensorturnBETA
Home › Data Cleaning & Analytics

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

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 strategyUse whenAvoid when
Random splitRows are independent and identically distributedData has time order or repeated entities
Stratified splitClassification with imbalanced classesRegression targets (use binned stratification instead if needed)
Time-based splitForecasting, or any model that predicts the future from the pastData has no meaningful time order
Group splitSeveral rows per customer, patient or deviceEach row is a separate entity
Cross-validationSmall datasets where one split is too noisyTime 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

TechniqueWhat it doesGood for
One-hot encodingOne binary column per categoryLow-cardinality categoricals, linear models and neural networks
Ordinal encodingMaps categories to integersOrdered categories, and tree models generally
Target encodingReplaces a category with a smoothed target statisticHigh-cardinality categoricals; must be fitted inside cross-validation to avoid leakage
Standard scalingZero mean, unit varianceLinear models, SVMs, neural networks, k-means, KNN
Min-max scalingRescales to a fixed rangeNeural networks and bounded inputs
Robust scalingCentres on the median and scales by IQRSkewed data with outliers
Log transformCompresses long right tailsHighly 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.

Start building free

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.