Artificial intelligence • Original RRTutors lesson
Data Quality, Features, and Preprocessing
Prepare model inputs while preserving meaning, provenance, and a clean separation between training and evaluation.
Concept and explanation
Features are representations used by a model. Missing values, inconsistent units, duplicates, outliers, and label errors can distort learning. Preprocessing must be fitted on training data and then applied unchanged to validation, test, and production data to prevent information leakage.
How to apply it
Profile data, document transformations, handle missingness deliberately, and test that training and inference use the same schema.
Worked example
A transaction model may normalize amounts and encode categories; the amount scale and category vocabulary should be learned from training data.
Illustrative Python example
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
model = make_pipeline(StandardScaler(), LogisticRegression())
model.fit(X_train, y_train)
Expected result
The pipeline fits scaling with the training data before fitting the classifier.
Limitations and cautions
Preprocessing can remove meaningful signals or expose sensitive attributes indirectly.
Practice exercise
Identify possible leakage in a dataset containing both transaction date and a post-outcome status field.
Key takeaway: Data preparation encodes assumptions and must be versioned and tested.