Data Science with Python Feature Engineering Techniques Flashcards
6 cards from real Data Science with Python Certification practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Data Science with Python Feature Engineering Techniques flashcards as text
A data scientist is preparing a dataset for a K-Nearest Neighbors (KNN) model. The dataset contains an 'age' feature (range 20-70) and an 'income' feature (range 30,000-250,000). Since KNN is a distance-based algorithm, what is the most appropriate feature scaling technique to apply and why?
Answer: Standardization (Z-score scaling), because it is less sensitive to outliers than Min-Max scaling and handles features on vastly different scales effectively.
Standardization (Z-score scaling) rescales features to have a mean of 0 and a standard deviation of 1. This is crucial for distance-based algorithms like KNN, where features with larger scales (like 'income') can dominate the distance calculation. Standardization is generally more robust to outliers than Min-Max scaling, which scales data to a fixed range (e.g., 0 to 1) and can be skewed by extreme values. [2, 7, 24]
You are working with a categorical feature 'product_category' which contains the values 'Electronics', 'Apparel', 'Home Goods', and 'Books'. There is no inherent order or ranking among these categories. Which encoding technique should be used to prepare this feature for a linear regression model to prevent the model from assuming a false ordinal relationship?
Answer: One-Hot Encoding, as it creates separate binary columns for each category, avoiding any implied ranking.
One-Hot Encoding is the correct choice for nominal categorical data (where no order exists) when used with linear models. It creates a new binary (0 or 1) feature for each category, preventing the model from incorrectly interpreting the categories as having a quantitative relationship (e.g., that 'Books' (encoded as 3) is greater than 'Apparel' (encoded as 1)). [19, 25, 26]
A dataset contains a 'last_login_date' column with a `datetime64[ns]` dtype. Which of the following feature engineering approaches is most effective for extracting cyclical patterns that could be useful for a predictive model?
Answer: Creating new numerical features such as 'day_of_week', 'month_of_year', and a binary 'is_weekend' flag.
Extracting components like the day of the week, month, or creating a flag for weekends allows a model to capture time-based patterns and seasonality (e.g., user activity might be higher on weekends or at the beginning of the month). This is a standard and highly effective technique for making datetime information useful to a model. [15, 18, 29]
A feature representing 'customer_spending' in a dataset is heavily right-skewed, with most values being low but with a long tail of very high-spending customers. Many linear machine learning models perform better with normally distributed features. What is a common and effective transformation to apply to this feature to make its distribution more symmetric?
Answer: Applying a logarithmic transformation (e.g., `np.log1p`) to compress the higher values and expand the lower values.
A logarithmic transformation is a powerful and common method for handling right-skewed data. It compresses the range of large values more than it compresses the range of small values, which effectively pulls the long tail in towards the center of the distribution, making it more symmetric and closer to a normal distribution. [1, 6, 14, 22]
What is a primary advantage of using binning (or discretization) to transform a continuous numerical feature, such as 'Age', into categorical bins (e.g., '18-25', '26-40', '41-60')?
Answer: It can help a linear model capture non-linear relationships between the feature and the target variable.
By converting a continuous feature into discrete bins, a model (especially a linear one) can learn a separate weight for each bin. This allows it to capture complex, non-linear patterns where the effect of the feature on the target variable changes across different ranges (e.g., the likelihood of purchasing a product might be high for the '18-25' age group, low for '26-40', and high again for '41-60'). [5, 8, 11, 16]
In a dataset for predicting house prices, you have features for 'num_bedrooms' and 'num_bathrooms'. Your initial model is underperforming, and you suspect the combined effect of these two features is more important than their individual effects. Which feature engineering technique would best capture this combined effect?
Answer: Creating an interaction feature, for example, by multiplying 'num_bedrooms' by 'num_bathrooms'.
Creating an interaction feature by multiplying 'num_bedrooms' and 'num_bathrooms' allows the model to learn the combined effect of these variables. This new feature can capture relationships that the individual features alone cannot, such as a house with many bedrooms AND many bathrooms being disproportionately more valuable. [3, 4, 17]
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy