Prompts Forms Resume Reports ★ Saved ★ Saved★ + Submit a tool
Techniques

Data Cleaning

About 2889 characters Updated Nov 30, 2026 29 views AI wiki

Data cleaning detects and corrects missing values, outliers, duplicates, format errors and inconsistencies in raw data before a model is trained or used. It is the first and most expensive step of preprocessing, and the ceiling of data quality often sets the ceiling of model performance.

Core Principles

Its essence is "using decidable rules to turn untrusted data into trusted data." It is not one algorithm but an ordered set of operations: profile first, measuring missing rate, unique values, types and ranges per column to find the "lesions," then choose a strategy per lesion.

For missing values the options are deletion (listwise, when the rate is under 5% and missingness is random), mean, median or mode imputation (simple but shrinks variance), model-based imputation (KNNImputer, or MissForest with iterative random-forest regression), and marking "missing" as a category to keep information. Outliers can be found by statistical rules (3-sigma, IQR), density methods (LOF) or residual analysis; afterward, separate "errors" from "genuine extremes," since deleting the latter is harmful.

Format and consistency problems are equally fatal: mixed date formats (2024/01/01 and 2024-01-01), inconsistent units (yuan and ten thousand yuan), garbled encoding, labels differing in case (Beijing and beijing) and stray spaces all break downstream aggregation and features. Text cleaning also removes HTML tags and control characters and unifies traditional and simplified Chinese and full-width and half-width characters.

Key Points

Profile before cleaning: use pandas-profiling, Great Expectations or Deequ for data profiles and assertions instead of writing scripts by intuition.

Fix at the source: change the ETL or collection side when possible; terminal scripts make every new batch repeat the work.

Reproducible rules: write processing as declarative config or versioned scripts, logging affected rows per step, so "why was this record deleted" can be traced.

New tasks for large models: pretraining pipelines include language identification (fastText classifiers), quality filtering (perplexity scores, heuristics such as symbol density and repeated n-gram ratio), harmful-content filtering (classifiers or blocklists) and sensitive masking (regex for ID numbers, phones, emails). The Gopher and C4 pipelines are key references.

Evolution runs from "manual rules plus Excel" to "scripting plus assertions," and now to "data contracts plus quality monitoring," shifting from cleanup to continuous observation.

Common Misconceptions

The most common is "always fill the mean" and "always delete outliers"; both distort the distribution, and when skew is heavy or the anomaly is the target (fraud, equipment failure), the deleted items are often the most valuable signal. The second is computing imputation statistics on all data, causing data leakage: fit on the training set, transform validation and test, and wrap the pipeline in sklearn's Pipeline so evaluation does not peek at test data. The third is over-cleaning, smoothing away meaningful noise and hurting robustness on real dirty data.

Application Scenarios

Table preprocessing before modeling, pretraining corpus filtering and decontamination, log and tracking governance, compliant masking of medical and financial data, format normalization before ingestion, and entity alignment in multi-source fusion.