# Feature Cross

> Combines multiple features to represent interaction effects explicitly

- **Category**: Machine Learning
- **Subcategory**: Data and Feature Representation
- **Canonical URL**: https://designpattern.fyi/patterns/feature-cross/

---

## Description
**Intent**: Enable simpler or linear models to learn interaction effects between features by explicitly creating combined features that represent joint occurrences.

**Context**: Linear models cannot natively learn that the combination of weekday and raining matters more for traffic than either feature alone. Deep models can learn interactions but may converge faster with explicit interaction signals.

**Solution**: Combine two or more features into a single new feature representing their joint occurrence. Continuous features are bucketed first so they can be crossed cleanly. The crossed feature turns a nonlinear relationship into a linear one over the crossed feature. If the resulting space is large, combine with hashing to bound its size.



## Use Cases
- Time-of-day and day-of-week crosses for traffic prediction
- User demographics and content category crosses for recommendations
- Geographic and seasonal crosses for demand forecasting
- Any domain where feature interactions are known to matter






## Trade-offs


### Advantages

- Enables linear models to capture interaction effects

- Can help deep models converge faster

- Makes feature interactions explicit and interpretable

- Turns nonlinear relationships into linear ones




### Considerations & Drawbacks

- Combinatorial growth in feature space

- Risk of overfitting to rare, specific combinations

- Adds complexity and requires careful feature selection

- May need hashing to control size for high-cardinality crosses







---
**Reference**: [Original Source](https://github.com/GoogleCloudPlatform/ml-design-patterns)

