When do feature crosses matter, and how do you control their complexity?
Written by the mlprep team · Updated
What are feature crosses? When would you explicitly create them instead of relying on a model to learn interactions?
What a feature cross is#
A feature cross combines two or more features to represent an interaction:
country = US, device = iOS -> country_US__device_iOS
The model can learn behavior specific to the combination, not just the separate effects of country and device.
Why crosses matter#
Linear models cannot learn interactions unless you provide them. If click behavior differs specifically for "new users on Android in India," separate linear weights for new user, Android, and India may miss the interaction.
Crosses are especially useful for sparse categorical systems: ads, search, recommendations, fraud, and personalization.
The danger#
Feature crosses explode combinatorially. A cross of two high-cardinality features can create millions of sparse features. Many will be rare, noisy, or unseen at serving.
Ways to control complexity:
- cross only features with clear product rationale
- require minimum support before creating a cross
- use hashing tricks for sparse crosses
- regularize heavily
- use embeddings for high-cardinality IDs
- compare against GBDTs or neural models that can learn interactions
Model choice#
GBDTs learn many feature interactions automatically through tree splits. Neural networks can learn interactions through embeddings and nonlinear layers, but may need more data. Linear models need explicit crosses.
Wide-and-deep models combine both: the wide part memorizes sparse crosses, and the deep part generalizes through embeddings.
Senior/staff considerations#
Feature crosses encode product assumptions. They can improve head segments while harming tail generalization. Monitor coverage: how often does a crossed feature appear at train and serve time? Unseen crosses should have fallback behavior.
In production, crosses can introduce train-serve skew if categorical normalization differs between training and serving. Version the vocabulary, hashing, and normalization rules.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
Feature crosses let models capture interactions, especially in linear or sparse categorical systems. They improve memorization but can explode cardinality and overfit. Use them with support thresholds, hashing, regularization, and careful train-serve consistency.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- Why do linear models need explicit feature crosses?
- When would embeddings be better than crossed one-hot features?
- How do feature crosses create train-serve skew?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
Walk me through feature engineering for tabular data
How do you encode categorical features? Compare one-hot, target encoding, and embeddings.
How do you handle missing data without introducing bias?
How would you design a feature store for a large ML platform?