Feature Engineering Lab
Building, selecting and reducing features.
- 3lessons
- 2experiments
- 5terms
Scientific introduction
Feature quality sets the ceiling on model performance. Learn to create useful features, pick the most informative and reduce dimensions with PCA, while watching for data leakage.
Learning objectives
- Create derived features and interactions
- Select features with statistical criteria
- Interpret PCA and explained variance
- Avoid leakage during selection and scaling
Topics
- Selection
- PCA
- Leakage
Core concepts
- Feature
- A variable used as an input to a model.
- Data leakage
- Information from test data or the future entering training, inflating measured performance.
- Principal component analysis
- Projection on orthogonal axes that maximise variance.
- Explained variance
- The share of data variance retained by an axis or set of axes.
- Curse of dimensionality
- Points spreading apart as dimensions grow, which weakens distance-based methods.
Theory
Creating features
Common ideas
Ratios (debt/income), time differences, group aggregates (a customer's average spend), interactions (product of two variables), bins (age bands) and log transforms.
Domain knowledge beats random trial. And beware: any feature derived from the target or from future information leaks information and produces misleading performance.
Feature selection
Three families
- Filter: rank each feature by an independent measure (correlation, F, mutual information).
- Wrapper: evaluate feature subsets by training a model.
- Embedded: select during training (for example Lasso regression).
Filters are fast but ignore interactions and redundancy. Selection must happen inside the cross-validation loop or test information leaks.
Principal component analysis
The idea
PCA finds orthogonal axes that maximise variance; they are the eigenvectors of the covariance matrix and each axis's variance is its eigenvalue. Explained-variance ratio of an axis = its eigenvalue ÷ the sum of eigenvalues.
Standardise features (z-score) first or large-unit variables dominate. The axes are linear combinations that can be hard to interpret, and PCA ignores the target variable.
Worked examples
Data leakage
Computing the scaling mean on all data before splitting leaks test information into training. The right way: fit statistics on training only and apply them to test.
Interactive experiments
Feature selection
Learning goal: Compare filter (correlation) and wrapper (forward) selection and notice the effect of noise.
Explanation and scientific documentation
Deliberate noise features are added, then k features are chosen by filter, forward selection or no selection, and model performance is measured on test data.
Data: Synthetic data generated in your browser with an editable seed; the relationships are planted on purpose for learning and are not real data.
A good feature clearly beats noise; if not, the measure or the signal is weak.
Limits: The filter is univariate and misses interactions; the wrapper is slower.
PCA visualisation
Learning goal: See the principal components, explained variance and the effect of standardisation.
Explanation and scientific documentation
The table is projected on the first two components and a cumulative explained-variance curve is shown.
Data: Synthetic data generated in your browser with an editable seed; the relationships are planted on purpose for learning and are not real data.
Eigenvalues of the covariance (or correlation, when standardised) matrix give each component's variance.
Limits: PCA is linear and ignores the target.
Related algorithms and methods
PCA
Projection on orthogonal axes that maximise variance.
Filter selection
Ranks features by a model-independent statistic.
Suitable datasets
- Customers (synthetic) Synthetic, generated in the browser
- Breast Cancer Wisconsin (Diagnostic) Link not verified yet
Practical projects
- Feature selection in high dimensions Advanced
Assessment questions
Sources and references
- Guyon, I., & Elisseeff, A. (2003). An introduction to variable and feature selection. Journal of Machine Learning Research, 3, 1157-1182 (bibliographic data entered by the editor, not machine-checked)
- Jolliffe, I. T., & Cadima, J. (2016). Principal component analysis: a review and recent developments. Philosophical Transactions of the Royal Society A, 374(2065) DOI (bibliographic data entered by the editor, not machine-checked)
- Pedregosa, F., et al. (2011). Scikit-learn: Machine learning in Python. Journal of Machine Learning Research, 12, 2825-2830 Link (bibliographic data entered by the editor, not machine-checked)
