Free Data Science Feature Engineering and Selection Questions and Answers 1 — Questions and Answers
Question 1: A data scientist is preparing a dataset with a categorical feature "City" ('New York', 'London', 'Tokyo'). The feature has high cardinality and no inherent order. Which encoding technique is most appropriate to convert this feature for a linear model without imposing a false ordinal relationship?
- Label Encoding
- One-Hot Encoding (Correct answer)
- Ordinal Encoding
- Log Transformation
Correct answer: One-Hot Encoding
One-Hot Encoding is the correct method for nominal categorical variables (where no order exists) that will be used in linear models. It creates new binary columns for each category, representing its presence or absence without implying any sort of ranking, which would be an incorrect assumption for a feature like 'City'.
Question 2: Which category of feature selection methods evaluates feature subsets by training and testing a specific machine learning model on each subset?
- Filter Methods
- Embedded Methods
- Intrinsic Methods
- Wrapper Methods (Correct answer)
Correct answer: Wrapper Methods
Wrapper methods use the performance of a chosen machine learning model to assess the quality of a subset of features. Methods like Recursive Feature Elimination (RFE) and Sequential Feature Selection (SFS) are classic examples where a model is repeatedly trained to find the optimal feature set.
Question 3: You are building a model using an algorithm that relies on distance calculations, such as K-Nearest Neighbors. Your dataset contains features with vastly different scales: 'Age' (18-90) and 'Annual_Income' (25,000-500,000). Which feature engineering step is most critical to ensure model performance is not biased by feature scale?
- Applying standardization or normalization. (Correct answer)
- Using one-hot encoding on the 'Age' feature.
- Creating interaction terms between 'Age' and 'Annual_Income'.
- Performing mean imputation for any missing values.
Correct answer: Applying standardization or normalization.
For distance-based algorithms, features with larger scales (like 'Annual_Income') can dominate the distance metric, making the contribution of features with smaller scales (like 'Age') insignificant. Standardization (e.g., StandardScaler) or normalization (e.g., MinMaxScaler) rescales features to a comparable range, ensuring that each feature contributes more equally to the result.
Question 4: A data scientist is working with a retail dataset that includes 'price_per_item' and 'quantity_sold' for each transaction. To improve a sales prediction model, they create a new feature called 'total_transaction_value' by multiplying these two features. What is this process an example of?
- Feature Binarization
- Feature Discretization
- Creating Interaction Features (Correct answer)
- Target Encoding
Correct answer: Creating Interaction Features
Creating a new feature by combining two or more existing features (through multiplication, division, addition, etc.) is known as creating an interaction feature. This technique can help a model capture a combined effect or relationship between variables that it might not find on its own.
Question 5: When dealing with missing numerical data in a feature that is known to have a skewed distribution with significant outliers, which imputation method is generally the most robust?
- Median Imputation (Correct answer)
- Mean Imputation
- Mode Imputation
- Constant Value Imputation (e.g., filling with zero)
Correct answer: Median Imputation
The mean is highly sensitive to outliers and skewness, as extreme values can distort it significantly. The median, representing the middle value of the sorted data, is not affected by the magnitude of outliers, making it a more robust and representative measure of central tendency for skewed distributions.
Question 6: Which of the following is a key characteristic of embedded feature selection methods?
- They are performed as a separate pre-processing step before any model is chosen.
- They rely on statistical tests like Chi-Squared or ANOVA to rank features.
- They are computationally the most expensive category of feature selection methods.
- The feature selection process is an intrinsic part of the model training algorithm itself. (Correct answer)
Correct answer: The feature selection process is an intrinsic part of the model training algorithm itself.
Embedded methods, such as L1 (Lasso) regularization and the feature importance calculated by tree-based models, perform feature selection naturally during the model fitting process. This is different from filter methods (pre-processing) and wrapper methods (which train a model multiple times).
A data scientist is preparing a dataset with a categorical feature "City" ('New York', 'London', 'Tokyo').
The feature has high cardinality and no inherent order.
Which encoding technique is most appropriate to convert this feature for a linear model without imposing a false ordinal relationship?