PROFESSIONAL-MACHINE-LEARNING-ENGINEER · Question #163
You are developing an ML model using a dataset with categorical input variables. You have randomly split half of the data into training and test sets. After applying one-hot encoding on the…
The correct answer is C. Apply one-hot encoding on the categorical variables in the test data. The correct approach is to apply one-hot encoding to the test set using the same vocabulary (set of category values) learned from the training set. If a category value present in training does not appear in the test set, the corresponding one-hot column will be all zeros for…
Question
Options
- AUse sparse representation in the test set.
- BRandomly redistribute the data, with 70% for the training set and 30% for the test set
- CApply one-hot encoding on the categorical variables in the test data
- DCollect more data representing all categories
How the community answered
(32 responses)- A3% (1)
- C91% (29)
- D6% (2)
Explanation
The correct approach is to apply one-hot encoding to the test set using the same vocabulary (set of category values) learned from the training set. If a category value present in training does not appear in the test set, the corresponding one-hot column will be all zeros for those test rows - which is valid and expected. This ensures the feature space is identical between train and test. Option A (sparse representation) doesn't resolve the encoding mismatch. Option B (re-splitting with 70/30) is arbitrary and may still produce a set missing that category. Option D (collecting more data) is unnecessary and not always feasible when the issue is simply that a category doesn't appear in the test sample.
Topics
Community Discussion
No community discussion yet for this question.